Python: What OS am I running on?

前端 未结 26 1570
野趣味
野趣味 2020-11-22 05:44

What do I need to look at to see whether I\'m on Windows or Unix, etc?

相关标签:
26条回答
  • 2020-11-22 06:29

    in the same vein....

    import platform
    is_windows=(platform.system().lower().find("win") > -1)
    
    if(is_windows): lv_dll=LV_dll("my_so_dll.dll")
    else:           lv_dll=LV_dll("./my_so_dll.so")
    
    0 讨论(0)
  • 2020-11-22 06:30

    You can also use only platform module without importing os module to get all the information.

    >>> import platform
    >>> platform.os.name
    'posix'
    >>> platform.uname()
    ('Darwin', 'mainframe.local', '15.3.0', 'Darwin Kernel Version 15.3.0: Thu Dec 10 18:40:58 PST 2015; root:xnu-3248.30.4~1/RELEASE_X86_64', 'x86_64', 'i386')
    

    A nice and tidy layout for reporting purpose can be achieved using this line:

    for i in zip(['system','node','release','version','machine','processor'],platform.uname()):print i[0],':',i[1]
    

    That gives this output:

    system : Darwin
    node : mainframe.local
    release : 15.3.0
    version : Darwin Kernel Version 15.3.0: Thu Dec 10 18:40:58 PST 2015; root:xnu-3248.30.4~1/RELEASE_X86_64
    machine : x86_64
    processor : i386
    

    What is missing usually is the operating system version but you should know if you are running windows, linux or mac a platform indipendent way is to use this test:

    In []: for i in [platform.linux_distribution(),platform.mac_ver(),platform.win32_ver()]:
       ....:     if i[0]:
       ....:         print 'Version: ',i[0]
    
    0 讨论(0)
提交回复
热议问题