Python:我正在运行什么操作系统?

时间:2020-03-05 18:37:39  来源:igfitidea点击:

我要查看我是否在Windows,Unix等操作系统上需要查看什么?

解决方案

回答

>>> import os
>>> print os.name
posix
>>> import platform
>>> platform.system()
'Linux'
>>> platform.release()
'2.6.22-15-generic'

platform.system()的输出如下:

  • Linux:Linux
  • Mac:Darwin
  • Windows:Windows

请参阅:平台访问基础平台的标识数据

回答

Dang -lbrandy击败了我,但这并不意味着我无法为我们提供Vista的系统结果!

>>> import os
>>> os.name
'nt'
>>> import platform
>>> platform.system()
'Windows'
>>> platform.release()
'Vista'

...而且我不敢相信还没有人针对Windows 10发布过一个:

>>> import os
>>> os.name
'nt'
>>> import platform
>>> platform.system()
'Windows'
>>> platform.release()
'10'

回答

为了记录,这是在Mac上的结果:

>>> import os
>>> os.name
'posix'
>>> import platform
>>> platform.system()
'Darwin'
>>> platform.release()
'8.11.1'

回答

如果我们已经导入了sys并且不想导入其他模块,则也可以使用sys.platform

>>> import sys
>>> sys.platform
'linux2'

回答

我做这个

import sys
print sys.platform

Docs在这里:sys.platform。

我们需要的所有内容都可能在sys模块中。

回答

我使用的是weblogic附带的WLST工具,它没有实现平台软件包。

wls:/offline> import os
wls:/offline> print os.name
java 
wls:/offline> import sys
wls:/offline> print sys.platform
'java1.5.0_11'

除了修补系统javaos.py(在Windows 2003上使用jdk1.5发行os.system())(我不能这样做,我必须开箱即用使用weblogic),这是我使用的:

def iswindows():
  os = java.lang.System.getProperty( "os.name" )
  return "win" in os.lower()