Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: What OS am I running on?

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

like image 728
Mark Harrison Avatar asked Aug 05 '08 03:08

Mark Harrison


People also ask

How do you check if os is Windows or Linux in Python?

system() Returns the system/OS name, e.g. 'Linux', 'Windows' or 'Java'. An empty string is returned if the value cannot be determined. If that isn't working, maybe try platform.

What os system does in Python?

Features of the Python OS System The OS system serves as a portable way of interacting with the underlying operating system. It offers access to file names, command line arguments, environment variables, process parameters, and filesystem hierarchy alongside other functionalities.


2 Answers

>>> import os >>> os.name 'posix' >>> import platform >>> platform.system() 'Linux' >>> platform.release() '2.6.22-15-generic' 

The output of platform.system() is as follows:

  • Linux: Linux
  • Mac: Darwin
  • Windows: Windows

See: platform — Access to underlying platform’s identifying data

like image 61
Louis Brandy Avatar answered Sep 23 '22 12:09

Louis Brandy


Dang -- lbrandy beat me to the punch, but that doesn't mean I can't provide you with the system results for Vista!

>>> import os >>> os.name 'nt' >>> import platform >>> platform.system() 'Windows' >>> platform.release() 'Vista' 

...and I can’t believe no one’s posted one for Windows 10 yet:

>>> import os >>> os.name 'nt' >>> import platform >>> platform.system() 'Windows' >>> platform.release() '10' 
like image 30
Joey deVilla Avatar answered Sep 24 '22 12:09

Joey deVilla