[Python-Dev] Recommended way to tell platform

Guido van Rossum guido at python.org
Sat Aug 7 18:37:00 CEST 2004


> A.M. Kuchling wrote:
> > Question: should the condition be sys.platform.startswith('win') for
> > the sake of win64, or other Windows variants?  (I don't know which
> > values sys.platform can have on Windows.)
> 
> Win64 also uses "win32" as sys.platform. If you really want to find
> out this is not x86, you need to look at the compiler ID in sys.version.
> 
> Regards,
> Martin

This does bring up an interesting question: what's the recommended way
to distinguish a certain platform?  There's os.name, sys.platform, the
platform module, and I've also seen code testing for os.sep=='/'.

I still prefer hasattr(<module>, <attribute>) whenever applicable,
e.g. preferring hasattr(os, 'fork') over os.name=='posix' (or
os.name!='nt' :-), but sometimes that's not possible.

What should be the preferred way?  (It may be impossible to say
because there are different use cases, but probably one of the most
important cases is simply distinguishing Windows from the rest -- how
should that be done?)

--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list