Reputation: 10686
I want to find out what OS a person has in Python. I know I could always do this:
try:
os.system(unixonlycommand)
except:
os.system(windowsonlycommand)
But is there another way to do it? A special module for that or something?
Upvotes: 0
Views: 272
Reputation: 176730
Use platform.system
:
Returns the system/OS name, e.g.
'Linux'
,'Windows'
, or'Java'
. An empty string is returned if the value cannot be determined.
You should also look at the other methods in the platform
module, depending on exactly what you're trying to do.
Also relevant: sys.platform
.
Upvotes: 5