detecting the operating system

Russell E. Owen no at spam.invalid
Tue Mar 2 20:32:08 CET 2004

In article <c1mtcj$ofv$1 at>,
 "Woojay Jeon" <wjj{nospam}eon at> wrote:

>OK, I tried a Google search on this Usenet group but couldn't find a
>solution, so I'm posting my question here (if there's a better archive than
>the one in Google, please let me know).
>Does anybody know how to detect the operating system under which the current
>Python program is running, especially whether it's Windows or Unix? I have a
>program that needs to search for files in "c:\test" if it's running under
>Windows, and "/home/user/test" if it's running under Unix, so the simplest
>solution I can think of is to detect the operating system, but if anyone
>could suggest a workaround, that would also be fine.

To simply differentiate between Windows and everything else, try 
importing a Windows-only library, such as _winreg or winsound:
    import _winreg
    # at this point it's some flavor of Windows
except ImportError:
    # not Windows

-- Russell

More information about the Python-list mailing list