Python: What OS am I running on?

前端 未结 26 2242
野趣味
野趣味 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:20

    For Jython the only way to get os name I found is to check os.name Java property (tried with sys, os and platform modules for Jython 2.5.3 on WinXP):

    def get_os_platform():
        """return platform name, but for Jython it uses os.name Java property"""
        ver = sys.platform.lower()
        if ver.startswith('java'):
            import java.lang
            ver = java.lang.System.getProperty("os.name").lower()
        print('platform: %s' % (ver))
        return ver
    

提交回复
热议问题