您好,欢迎访问一九零五行业门户网

Python判断操作系统类型代码分享

经常地我们需要编写跨平台的脚本,但是由于不同的平台的差异性,我们不得不获得当前所工作的平台(操作系统类型)。
代码如下:
复制代码 代码如下:
import platformdef testplatform():
    print (----------operation system--------------------------)
    #windows will be : (32bit, windowspe)
    #linux will be : (32bit, elf)
    print(platform.architecture())
    #windows will be : windows-xp-5.1.2600-sp3 or windows-post2008server-6.1.7600
    #linux will be : linux-2.6.18-128.el5-i686-with-redhat-5.3-final
    print(platform.platform())
    #windows will be : windows
    #linux will be : linux
    print(platform.system())
    print (--------------python version-------------------------)
    #windows and linux will be : 3.1.1 or 3.1.3
    print(platform.python_version())
def useplatform():
  sysstr = platform.system()
  if(sysstr ==windows):
    print (call windows tasks)
  elif(sysstr == linux):
    print (call linux tasks)
  else:
    print (other system tasks)
useplatform()
其它类似信息

推荐信息