What do I need to look at to see whether I\'m on Windows or Unix, etc?
/usr/bin/python3.2
def cls():
from subprocess import call
from platform import system
os = system()
if os == 'Linux':
call('clear', shell = True)
elif os == 'Windows':
call('cls', shell = True)
For Jython the only way to get os name I found is to check os.name
Java property (tried with sys
, os
and platform
modules for Jython 2.5.3 on WinXP):
def get_os_platform():
"""return platform name, but for Jython it uses os.name Java property"""
ver = sys.platform.lower()
if ver.startswith('java'):
import java.lang
ver = java.lang.System.getProperty("os.name").lower()
print('platform: %s' % (ver))
return ver
Check the available tests with module platform and print the answer out for your system:
import platform
print dir(platform)
for x in dir(platform):
if x[0].isalnum():
try:
result = getattr(platform, x)()
print "platform."+x+": "+result
except TypeError:
continue
Interesting results on windows 8:
>>> import os
>>> os.name
'nt'
>>> import platform
>>> platform.system()
'Windows'
>>> platform.release()
'post2008Server'
Edit: That's a bug
How about a new answer:
import psutil
psutil.MACOS #True (OSX is deprecated)
psutil.WINDOWS #False
psutil.LINUX #False
This would be the output if I was using MACOS
I am using the WLST tool that comes with weblogic, and it doesn't implement the platform package.
wls:/offline> import os
wls:/offline> print os.name
java
wls:/offline> import sys
wls:/offline> print sys.platform
'java1.5.0_11'
Apart from patching the system javaos.py (issue with os.system() on windows 2003 with jdk1.5) (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 "win" in os.lower()