detecting the operating system

Peter Otten __peter__ at web.de
Fri Feb 27 10:53:59 CET 2004


Woojay Jeon wrote:

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

Instead of sys.platform, os.name might be helpful as it is less specific. I
think you will get os.name == "posix" for Unix/Linux etc. and os.name ==
"nt" for win32.

Peter



More information about the Python-list mailing list