How do I check the operating system in Python?

前端 未结 5 2029
情书的邮戳
情书的邮戳 2020-12-04 06:18

I want to check the operating system (on the computer where the script runs).

I know I can use os.system(\'uname -o\') in Linux, but it gives me a messa

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 07:01

    If you want to know on which platform you are on out of "Linux", "Windows", or "Darwin" (Mac), without more precision, you should use:

    >>> import platform
    >>> platform.system()
    'Linux'  # or 'Windows'/'Darwin'
    

    The platform.system function uses uname internally.

提交回复
热议问题