Python: What OS am I running on?

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

    Use platform.system()

    Returns the system/OS name, such as 'Linux', 'Darwin', 'Java', 'Windows'. An empty string is returned if the value cannot be determined.

    import platform
    system = platform.system().lower()
    
    is_windows = system == 'windows'
    is_linux = system == 'linux'
    is_mac = system == 'darwin'
    

提交回复
热议问题