Home » Questions » Computers [ Ask a new question ]

Python: What OS am I running on?

Python: What OS am I running on?

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

Asked by: Guest | Views: 43
Total answers/comments: 4
Guest [Entry]

">>> 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"
Guest [Entry]

"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'"
Guest [Entry]

"For the record here's the results on Mac:

>>> import os
>>> os.name
'posix'
>>> import platform
>>> platform.system()
'Darwin'
>>> platform.release()
'8.11.1'"
Guest [Entry]

"Sample code to differentiate OS's using python:

from sys import platform as _platform

if _platform == ""linux"" or _platform == ""linux2"":
# linux
elif _platform == ""darwin"":
# MAC OS X
elif _platform == ""win32"":
# Windows
elif _platform == ""win64"":
# Windows 64-bit"