파이썬에서 현재 OS를 어떻게 찾을 수 있습니까? [복제]
가능한 중복 :
Python : 어떤 OS를 실행하고 있습니까?
제목에서 알 수 있듯이 파이썬에서 현재 운영 체제를 어떻게 찾을 수 있습니까?
나는 보통 플랫폼을 얻기 위해 sys.platform
( docs )를 사용 합니다. sys.platform
리눅스, 다른 유닉스와 OS X를 구별 할 것이며, os.name
" posix
"는 모두 " "입니다.
보다 자세한 정보는 플랫폼 모듈을 사용하십시오 . 여기에는 기계 아키텍처, OS 및 OS 버전, Python 버전 등에 대한 정보를 제공하는 크로스 플랫폼 기능이 있습니다. 또한 특정 Linux 배포판과 같은 것을 얻는 os 특정 기능이 있습니다.
사용자가 읽을 수있는 데이터를 원하지만 여전히 자세한 정보가 필요한 경우 platform.platform ()
>>> import platform
>>> platform.platform()
'Linux-3.3.0-8.fc16.x86_64-x86_64-with-fedora-16-Verne'
platform
다른 유용한 방법도 있습니다.
>>> platform.system()
'Windows'
>>> platform.release()
'XP'
>>> platform.version()
'5.1.2600'
현재 위치를 식별하기 위해 사용할 수있는 몇 가지 다른 호출이 있습니다.
import platform
import sys
def linux_distribution():
try:
return platform.linux_distribution()
except:
return "N/A"
print("""Python version: %s
dist: %s
linux_distribution: %s
system: %s
machine: %s
platform: %s
uname: %s
version: %s
mac_ver: %s
""" % (
sys.version.split('\n'),
str(platform.dist()),
linux_distribution(),
platform.system(),
platform.machine(),
platform.platform(),
platform.uname(),
platform.version(),
platform.mac_ver(),
))
이 스크립트의 출력은 몇 가지 다른 시스템 (Linux, Windows, Solaris, MacOS)에서 실행되었으며 아키텍처 (x86, x64, Itanium, power pc, sparc)는 https://github.com/hpcugent/easybuild/에서 사용할 수 있습니다. wiki / OS_flavor_name_version
import os
print os.name
이것은 일반적으로 필요한 필수 정보를 제공합니다. 예를 들어, 서로 다른 Windows 에디션을 구별하려면 플랫폼 별 방법을 사용해야합니다.
https://docs.python.org/library/os.html
Greg의 게시물을 보완하기 위해 MacOS, Linux, Unix 등을 포함하는 posix 시스템을 사용하는 경우 os.uname ()을 사용하여 어떤 종류의 시스템인지 더 잘 느낄 수 있습니다.
라인을 따라 뭔가 :
import os
if (os.name == "posix"):
print os.system("uname -a")
# insert other possible OSes here
# ...
else:
print "unknown OS"
참고 URL : https://stackoverflow.com/questions/110362/how-can-i-find-the-current-os-in-python
'Programing' 카테고리의 다른 글
ScrollView Touch 처리 내의 HorizontalScrollView (0) | 2020.04.20 |
---|---|
올바른 "this"컨텍스트를 setTimeout 콜백에 전달 하시겠습니까? (0) | 2020.04.20 |
Pandas 데이터 프레임에서 행 목록을 삭제하는 방법은 무엇입니까? (0) | 2020.04.20 |
디렉토리에서 모든 PHP 파일을 포함시키는 방법은 무엇입니까? (0) | 2020.04.20 |
Swift의 첫 번째 ViewController에서 탐색 막대를 숨기는 방법은 무엇입니까? (0) | 2020.04.20 |