detecting the operating system

Michael mogmios at mlug.missouri.edu
Sat Feb 28 23:34:26 CET 2004


Checking sys.platform is easy enough. I use it to figure out if I'm 
running on Linux or Windows. For Linux I take the users home directory 
to put files in. In Windows I check the registry to find out the 
location of My Documents and then save files there. Checking the Windows 
registry is a little more work but can make your programs work quite 
nicely in Windows.

>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.
>




More information about the Python-list mailing list