Python: What OS am I running on?

我需要看看我是否在Windows,Unix等?


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

The output of platform.system() is as follows:

  • Linux: Linux
  • Mac: Darwin
  • Windows: Windows
  • See: platform — Access to underlying platform's identifying data


    Dang -- lbrandy beat me to the punch, but that doesn't mean I can't provide you with the system results for Vista!

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

    ...and I can't believe no one's posted one for Windows 10 yet:

    >>> 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'
    
    链接地址: http://www.djcxy.com/p/20004.html

    上一篇: 如何在Python中获取文件创建和修改日期/时间?

    下一篇: Python:我在运行什么操作系统?