How can I find the current OS in Python?
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Sunrise at the Stream
--
Chapters
00:00 How Can I Find The Current Os In Python?
00:13 Answer 1 Score 21
00:27 Answer 2 Score 56
00:40 Accepted Answer Score 348
01:10 Answer 4 Score 14
01:18 Thank you
--
Full question
https://stackoverflow.com/questions/1103...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #crossplatform #platformspecific
#avk47
ACCEPTED ANSWER
Score 348
I usually use sys.platform to get the platform. sys.platform will distinguish between linux, other unixes, and OS X, while os.name is "posix" for all of them.
For much more detailed information, use the platform module. This has cross-platform functions that will give you information on the machine architecture, OS and OS version, version of Python, etc. Also it has os-specific functions to get things like the particular linux distribution.
ANSWER 2
Score 56
import os
print(os.name)
This gives you the essential information you will usually need. To distinguish between, say, different editions of Windows, you will have to use a platform-specific method.
ANSWER 3
Score 21
https://docs.python.org/library/os.html
To complement Greg's post, if you're on a posix system, which includes MacOS, Linux, Unix, etc. you can use os.uname() to get a better feel for what kind of system it is.
ANSWER 4
Score 14
Something along the lines:
import os
if os.name == "posix":
    print(os.system("uname -a"))
# insert other possible OSes here
# ...
else:
    print("unknown OS")