detecting the operating system

Peter Hansen peter at
Fri Feb 27 15:30:14 CET 2004

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

Would it be somewhat easier just to pass in the directory as a command
line argument?  That way you (a) don't need to have hardcoded paths, (b)
don't need the platform-detection logic, and (c) can more easily change
it in the inevitable case that it needs to change someday.


More information about the Python-list mailing list