How Can I Determine the Operating System with Python?

Steven Majewski sdm7g at Virginia.EDU
Thu Mar 21 16:03:41 EST 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
> 'mac'
> >>> import os
> >>> os.environ
> {}
> >>> os.name
> 'mac'
>
> 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
>>> sys.platform
'darwin'
>>> os.name
'posix'

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
>>> sys.platform
'mac'
>>> os.name
'mac'


-- Steve Majewski





More information about the Python-list mailing list