Billjk
Billjk

Reputation: 10686

How can you find out what operating system the user is running?

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

Answers (1)

agf
agf

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

Related Questions