是否使用platform.system
?
system()
Returns the system/OS name, e.g. 'Linux', 'Windows' or 'Java'.
An empty string is returned if the value cannot be determined.
如果不工作,也许尝试platform.win32_ver
,如果它不抛出异常,您使用的是Windows;但我不知道它是否向前兼容64位,因为它的名称中有32个。
win32_ver(release='', version='', csd='', ptype='')
Get additional version information from the Windows Registry
and return a tuple (version,csd,ptype) referring to version
number, CSD level and OS type (multi/single
processor).
但os.name
可能是其他人提到的方法。
对于它的价值,这里有几个他们platform.py检查Windows的方式:
if sys.platform == 'win32':
#---------
if os.environ.get('OS','') == 'Windows_NT':
#---------
try: import win32api
#---------
# Emulation using _winreg (added in Python 2.0) and
# sys.getwindowsversion() (added in Python 2.3)
import _winreg
GetVersionEx = sys.getwindowsversion
#----------
def system():
""" Returns the system/OS name, e.g. 'Linux', 'Windows' or 'Java'.
An empty string is returned if the value cannot be determined.
"""
return uname()[0]
类似于http://计算器。com/questions/196930/how-to-check-if-os-is-vista-in-python – monkut 2009-08-25 01:27:14
“应该有一个 - 最好只有一个 - 明显的方法来做到这一点。”唉,Python给了我们至少三种方法.. – 2009-08-25 01:35:33