How Can I Determine the Operating System with Python?

Martin v. Loewis martin at v.loewis.de
Thu Mar 21 01:20:35 EST 2002


obsidian_genius at yahoo.com (Jill Obsidian) writes:

> I have need to write some Python scripts that run on Windows as well
> as Linux/Unix.
> 
> In some instances I will be making os.system() calls to execute
> applications installed locally on the machine.
> 
> How can I put a check in my script which will allow me to determine
> whether I'm running on Windows or Linux at execution time?

If you want to run an executable, don't check for the system - check
whether the executable exists: os.path.exists("/bin/ps").

HTH,
Martin



More information about the Python-list mailing list