How do I check the operating system in Python?

前端 未结 5 2032
情书的邮戳
情书的邮戳 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 06:45

    You can get a pretty coarse idea of the OS you're using by checking sys.platform.

    Once you have that information you can use it to determine if calling something like os.uname() is appropriate to gather more specific information. You could also use something like Python System Information on unix-like OSes, or pywin32 for Windows.

    There's also psutil if you want to do more in-depth inspection without wanting to care about the OS.

提交回复
热议问题