[Python-Dev] Recommended way to tell platform
Guido van Rossum
guido at python.org
Sat Aug 7 23:11:08 CEST 2004
> [Guido]
> > 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=='/'.
[Tim]
> I ask myself that question every time I need to do it. Out of sheer
> momentum now, I almost always use
>
> if sys.platform in ('win32',):
Why the 'in singleton tuple'? Still holding out for that compiler
optimization that promises to make tuples of constants code constants
themselves?
> I dislike using os.name == 'nt', mostly because if we asked all
> Windows Python users which OS they use, only a tiny percentage would
> answer "NT". Since NT is a dying OS, 'nt' is an increasingly
> odd-looking thing to test agaist.
And so is 'posix' when you're looking at Linux. :-)
We can't change these values easily so they will look odder and odder
as time progresses.
> OTOH, I have no idea when or why sys.platform == "win32" would give
> a different result than os.name == "nt".
Maybe on cygwin? I really don't know.
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev
mailing list