How to tell if you're running on windows?

zeph zephjc at gmail.com
Fri Dec 4 14:19:47 EST 2009


On Dec 4, 10:46 am, Roy Smith <r... at panix.com> wrote:
> I'm using 2.5.1.  How can I tell if I'm running on windows?  The
> obvious answer, platform.system(), gets complicated.  On the python
> that comes with cygwin, it returns 'CYGWIN_NT-5.2-WOW64', but I've got
> a native windows build of python where it returns 'Microsoft'.
>
> The real problem I'm trying to solve is whether to build a LIBPATH
> environment variable with ';' or ':' delimiting the entries.  On the
> cygwin build, os.pathsep returns ':', which isn't really correct.  If
> you use that, you end up building paths that look like c:foo:c:bar.
> It should be c:foo;c:bar

The Cygwin shell uses what appears to be its own pseudo-filesystem. If
you open your Cygwin shell window and type echo $PATH you will see
completely different results from the Windows command shell's PATH env
variable, and you'll see the path sep is indeed ':'.

Cygwin also seems to put drive mount points in /cygdrive/ so you will
have for example "/cygdrive/c/foo:/cygdrive/c/bar" instead of "C:
\foo;C:\bar".

For python *outside* of Cygwin, on Windows, I assume os.path.pathsep
is ';'.

- zeph



More information about the Python-list mailing list