Python is open source, and will run a a multitude of platforms including, but not limited to: Various Linux/UNIX distributions (CentOS, Ubuntu, Fedora, Debian, etc.), Microsoft Windows, and Mac OS X. Pre-Flight Check.
Sys has some useful stuff: $ python Python 2.6.6 (r266:84297, Aug 24 2010, 18:13:38) MSC v.1500 64 bit (AMD64) on win32 Type 'help', 'copyright', 'credits' or 'license' for more information. import sys sys.executable 'c: Python26 python.exe' sys.execprefix 'c: Python26' print ' n'.join(sys.path) c: Python26 lib site-packages setuptools-0.6c11-py2.6.egg c: Python26 lib site-packages nose-1.0.0-py2.6.egg C: Windows system32 python26.zip c: Python26 DLLs c: Python26 lib c: Python26 lib plat-win c: Python26 lib lib-tk c: Python26 c: Python26 lib site-packages c: Python26 lib site-packages win32 c: Python26 lib site-packages win32 lib c: Python26 lib site-packages Pythonwin c: Python26 lib site-packages wx-2.8-msw-unicode.
On Dec 13, 6:32 pm, 'Ian F. Hood wrote: Hi In typically windows environments I have used: if 'Windows' in os.environ'OS'. To prove it, but now I need to properly support different environments. To do so I must accurately determine what system the python instance is running on (linux, win, mac, etc).
Is there a best practises way to do this? TIA Ian The more significant question is 'why' do you want to do this?
Are you writing an asset management tool? Do you just want to tell the user what operating system they are using? The reason may lead to a different solution.
![Windows Windows](/uploads/1/2/5/4/125459744/627983091.png)
I am integrating with an existing cross-platform system that provides different shell scripts and/or batch files for each environment. Normally the selection is performed manually but my utility needs to automate this.
To select the correct utility I need to know what platform my code is running on. 'Paul Watson' Hi In typically windows environments I have used: if 'Windows' in os.environ'OS'. To prove it, but now I need to properly support different environments.
To do so I must accurately determine what system the python instance is running on (linux, win, mac, etc). Is there a best practises way to do this? TIA Ian The more significant question is 'why' do you want to do this?
Are you writing an asset management tool? Do you just want to tell the user what operating system they are using? The reason may lead to a different solution. Excellent, ty On Dec 13, 6:32 pm, 'Ian F.
Hood' Hi In typically windows environments I have used: if 'Windows' in os.environ'OS'. To prove it, but now I need to properly support different environments. To do so I must accurately determine what system the python instance is running on (linux, win, mac, etc). Is there a best practises way to do this? TIA Ian I would do this: - if os.name 'posix': linuxStuff elif os.name 'nt': windowsStuff elif os.name 'os2'.
os.name is 'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos' -N. On 2006-12-13 19:28:14 -0500, said: On Dec 13, 6:32 pm, 'Ian F. Hood' Hi In typically windows environments I have used: if 'Windows' in os.environ'OS'. To prove it, but now I need to properly support different environments. To do so I must accurately determine what system the python instance is running on (linux, win, mac, etc).
Is there a best practises way to do this? TIA Ian I would do this: - if os.name 'posix': linuxStuff elif os.name 'nt': windowsStuff elif os.name 'os2'. os.name is 'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos' -N Bearing in mind, of course, that Mac will return 'posix', too. And Cygwin might.
Also try: sys.platform if sys.platform 'darwin': macStuff elif sys.platform 'win32': linuxStuff James Cunningham wrote: On 2006-12-13 19:28:14 -0500, said: On Dec 13, 6:32 pm, 'Ian F. If sys.platform 'darwin': macStuff elif sys.platform 'win32': winStuff Not sure what the string is on linux. Just fire up the interpreter and try it. Prateek Prateek wrote: also try: sys.platform if sys.platform 'darwin': macStuff elif sys.platform 'win32': linuxStuff James Cunningham wrote: On 2006-12-13 19:28:14 -0500, said: On Dec 13, 6:32 pm, 'Ian F. Hood' Hi In typically windows environments I have used: if 'Windows' in os.environ'OS'.
to prove it, but now I need to properly support different environments. To do so I must accurately determine what system the python instance is running on (linux, win, mac, etc). Is there a best practises way to do this? TIA Ian I would do this: - if os.name 'posix': linuxStuff elif os.name 'nt': windowsStuff elif os.name 'os2'. os.name is 'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos' -N Bearing in mind, of course, that Mac will return 'posix', too. And Cygwin might.