How to tell if you're running on windows?

r0g aioe.org at technicalbloke.com
Sat Dec 5 15:16:41 EST 2009


Roy Smith 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


Hi,

Never used cygwin so I have no idea if this will work for you but I have
been using the following...

if getattr(sys, "getwindowsversion", None) is None:
    print "Not on Windows, Whoop! :)"
else:
    print "Oh dear :-/"


Roger.



More information about the Python-list mailing list