How Can I Determine the Operating System with Python?
sdm7g at Virginia.EDU
Thu Mar 21 22:03:41 CET 2002
On Thu, 21 Mar 2002, David Eppstein wrote:
> In article <mailman.1016735254.27977.python-list at python.org>,
> Cliff Wells <logiplexsoftware at earthlink.net> wrote:
> > > >>> os.environ['OS']
> > > 'Windows_NT'
> > >
> > > No idea what it does on other platforms.
> > It depends upon whether the environment variable "OS" is present, so it's
> > probably less reliable than sys.platform (doesn't exist on RH Linux, at
> > least).
> Another one where os.environ['OS'] doesn't exist:
> >>> import sys
> >>> sys.platform
> >>> import os
> >>> os.environ
> >>> os.name
> Not sure how you're supposed to distinguish Classic from Darwin...
On OSX, running the command-line (unix) mach-o python:
Python 2.2.1c1 (#1, Mar 19 2002, 02:06:22)
[GCC 2.95.2 19991024 (release)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os,sys
But running the carbonized MacPython on OSX yields same as Classic:
Python 2.2 (#123, Dec 22 2001, 00:11:59) [CW CARBON GUSI2 THREADS GC] on mac
Type "copyright", "credits" or "license" for more information.
>>> import sys,os
-- Steve Majewski
More information about the Python-list