tags:

views:

2669

answers:

3

As the title says how can I find the current OS in python?

+6  A: 

http://python.org/doc/2.5/lib/module-os.html

To compliment 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.

bmdhacks
Although your answer was fist and was correct, Greg Hewgill's answer was more complete, I appreciate your answer and advise you to, post more then just links, in the future.
Unkwntech
Yeah, it's the fastest gun in the west problem. I tend to post things quickly then edit with more info.
bmdhacks
I usually wait to answer my questions an I come back to them to see if there are any better posts even after I have accepted one.
Unkwntech
+15  A: 
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.

Greg Hewgill
On the mac, os.name gives "posix", which for my case does not help - sys.platform did the trick
Steg
+15  A: 

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.

dF