tags:

views:

1884

answers:

7

What do I need to look at to see if I'm on Windows, Unix, etc?

+33  A: 
>>> import os
>>> print os.name
posix
>>> import platform
>>> platform.system()
'Linux'
>>> platform.release()
'2.6.22-15-generic'

See: http://docs.python.org/lib/node441.html

lbrandy
+15  A: 

Dang -- lbrandy beat me to the punch, but that doesn't mean I can't provide you with the system results for Vista!

>>> import os
>>> print os.name
nt
>>> import platform
>>> platform.system()
'Windows'
>>> platform.release()
'Vista'
Joey deVilla
+7  A: 

Thanks all, for the record here's the results on Mac:

>>> import os
>>> os.name
'posix'
>>> import platform
>>> platform.system()
'Darwin'
>>> platform.release()
'8.11.1'
Mark Harrison
+5  A: 

You can also use sys.platform if you already have imported sys and you don't want to import another module

>>> import sys
>>> sys.platform
'linux2'
Moe
+4  A: 

I do this

import sys
print sys.platform

Docs here : http://docs.python.org/library/sys.html#sys.platform. Everything you need is probably in the sys module.

ggambett
+3  A: 

This question has already been answered before: http://stackoverflow.com/questions/1854/python-how-do-i-tell-what-os-im-running-on

Patrick Daryll Glandien
A: 

I am using the WLST tool that comes with weblogic, and it doesn't implement the platform package.

Apart from patching the system javaos.py (http://osdir.com/ml/lang.jython.devel/2006-08/msg00035.html) (which I can't do, I have to use weblogic out of the box), this is what I use:

def iswindows():
  os = java.lang.System.getProperty( "os.name" )
  return os.lower().find("win") > -1
Alftheo