0

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?

agf
  • 171,228
  • 44
  • 289
  • 238
Billjk
  • 10,387
  • 23
  • 54
  • 73
  • 1
    Reviewing this post might be helpful. http://stackoverflow.com/questions/1421357/how-do-i-get-the-operating-system-name-in-a-friendly-manner-using-python-2-5 – Colin D Apr 06 '12 at 13:52

1 Answers1

5

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.

agf
  • 171,228
  • 44
  • 289
  • 238