faqts : Computers : Programming : Languages : Python : Common Problems

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

7 of 8 people (88%) answered Yes
Recently 6 of 7 people (86%) answered Yes

Entry

Is there a way how I can identify the operating system my Python script is running on (e.g., Linux, Windows, Mac, ...)?

Jul 16th, 2000 21:32
unknown unknown, Emile van Sebille, Mahogany Rush, Matthew Schinckel


Look for Marc Lemburg's platform.py, or use the standard sys.platform.
Python 1.6a2 (#1, May 14 2000, 08:15:17)  [GCC 2.8.1] on sunos5
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import sys
>>> sys.platform
'sunos5'
If it is only for compatibilty reasons, you can use os.name.
This will give you one of: ['posix', 'nt', 'dos', 'mac', 'os2', 'ce'].