How do I check the operating system in Python?

The Solution to How do I check the operating system in Python? is


You can use sys.platform:

from sys import platform
if platform == "linux" or platform == "linux2":
    # linux
elif platform == "darwin":
    # OS X
elif platform == "win32":
    # Windows...

sys.platform has finer granularity than sys.name.

For the valid values, consult the documentation.

See also the answer to “What OS am I running on?”

~ Answered on 2011-11-21 23:45:16


Most Viewed Questions: