364,111 Members | 2059 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

how to determine Operating System in Use?

Ian F. Hood
P: n/a
Ian F. Hood
Hi
In typically windows environments I have used:
if 'Windows' in os.environ['OS']...
to prove it, but now I need to properly support different environments.
To do so I must accurately determine what system the python instance is
running on (linux, win, mac, etc).
Is there a best practises way to do this?
TIA
Ian



Dec 14 '06 #1
Share this Question
Share on Google+
7 Replies


nanjundi@gmail.com
P: n/a
nanjundi@gmail.com


On Dec 13, 6:32 pm, "Ian F. Hood" <IanFH...@gmail.comwrote:
Hi
In typically windows environments I have used:
if 'Windows' in os.environ['OS']...
to prove it, but now I need to properly support different environments.
To do so I must accurately determine what system the python instance is
running on (linux, win, mac, etc).
Is there a best practises way to do this?
TIA
Ian
I would do this:
--------------------
if os.name == ''posix':
linuxStuff()
elif os.name == 'nt':
windowsStuff()
elif os.name == 'os2': ...
-------------------
os.name is 'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos'

-N

Dec 14 '06 #2

Paul Watson
P: n/a
Paul Watson
Ian F. Hood wrote:
Hi
In typically windows environments I have used:
if 'Windows' in os.environ['OS']...
to prove it, but now I need to properly support different environments.
To do so I must accurately determine what system the python instance is
running on (linux, win, mac, etc).
Is there a best practises way to do this?
TIA
Ian
The more significant question is "why" do you want to do this? Are you
writing an asset management tool? Do you just want to tell the user
what operating system they are using? The reason may lead to a
different solution.
Dec 14 '06 #3

Ian F. Hood
P: n/a
Ian F. Hood
I am integrating with an existing cross-platform system that provides
different shell scripts and/or batch files for each environment. Normally
the selection is performed manually but my utility needs to automate this.
To select the correct utility I need to know what platform my code is
running on.

"Paul Watson" <pwatson@redlinepy.comwrote in message
news:4ubttfF17m7vaU1@mid.individual.net...
Ian F. Hood wrote:
>Hi
>In typically windows environments I have used:
> if 'Windows' in os.environ['OS']...
>to prove it, but now I need to properly support different environments.
>To do so I must accurately determine what system the python instance is
>running on (linux, win, mac, etc).
>Is there a best practises way to do this?
>TIA
>Ian
>
The more significant question is "why" do you want to do this? Are you
writing an asset management tool? Do you just want to tell the user
what operating system they are using? The reason may lead to a
different solution.
--
http://mail.python.org/mailman/listinfo/python-list
>


Dec 14 '06 #4

Ian F. Hood
P: n/a
Ian F. Hood
excellent, ty

<nanjundi@gmail.comwrote in message
news:1166056094.751283.122760@79g2000cws.googlegro ups.com...
>
>
On Dec 13, 6:32 pm, "Ian F. Hood" <IanFH...@gmail.comwrote:
>Hi
>In typically windows environments I have used:
> if 'Windows' in os.environ['OS']...
>to prove it, but now I need to properly support different environments.
>To do so I must accurately determine what system the python instance is
>running on (linux, win, mac, etc).
>Is there a best practises way to do this?
>TIA
>Ian
>
I would do this:
--------------------
if os.name == ''posix':
linuxStuff()
elif os.name == 'nt':
windowsStuff()
elif os.name == 'os2': ...
-------------------
os.name is 'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos'
>
-N
>
--
http://mail.python.org/mailman/listinfo/python-list
>


Dec 14 '06 #5

James Cunningham
P: n/a
James Cunningham
On 2006-12-13 19:28:14 -0500, nanjundi@gmail.com said:
>
>
On Dec 13, 6:32 pm, "Ian F. Hood" <IanFH...@gmail.comwrote:
>Hi
>In typically windows environments I have used:
>if 'Windows' in os.environ['OS']...
>to prove it, but now I need to properly support different environments.
>To do so I must accurately determine what system the python instance is
>running on (linux, win, mac, etc).
>Is there a best practises way to do this?
>TIA
>Ian
>
I would do this:
--------------------
if os.name == ''posix':
linuxStuff()
elif os.name == 'nt':
windowsStuff()
elif os.name == 'os2': ...
-------------------
os.name is 'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos'
>
-N
Bearing in mind, of course, that Mac will return "posix", too. And
Cygwin might. Erg.

Best,
James

Dec 14 '06 #6

Prateek
P: n/a
Prateek
also try:

sys.platform

if sys.platform == "darwin":
macStuff()
elif sys.platform == "win32":
linuxStuff()


James Cunningham wrote:
On 2006-12-13 19:28:14 -0500, nanjundi@gmail.com said:
>


On Dec 13, 6:32 pm, "Ian F. Hood" <IanFH...@gmail.comwrote:
Hi
In typically windows environments I have used:
if 'Windows' in os.environ['OS']...
to prove it, but now I need to properly support different environments.
To do so I must accurately determine what system the python instance is
running on (linux, win, mac, etc).
Is there a best practises way to do this?
TIA
Ian
I would do this:
--------------------
if os.name == ''posix':
linuxStuff()
elif os.name == 'nt':
windowsStuff()
elif os.name == 'os2': ...
-------------------
os.name is 'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos'

-N
>
Bearing in mind, of course, that Mac will return "posix", too. And
Cygwin might. Erg.
>
Best,
James
Dec 14 '06 #7

Prateek
P: n/a
Prateek
eeps! typo.
if sys.platform == "darwin":
macStuff()
elif sys.platform == "win32":
winStuff()
>
Not sure what the string is on linux. Just fire up the interpreter and
try it.

Prateek

Prateek wrote:
also try:
>
sys.platform
>
if sys.platform == "darwin":
macStuff()
elif sys.platform == "win32":
linuxStuff()
>
>
James Cunningham wrote:
On 2006-12-13 19:28:14 -0500, nanjundi@gmail.com said:
>
>
On Dec 13, 6:32 pm, "Ian F. Hood" <IanFH...@gmail.comwrote:
>Hi
>In typically windows environments I have used:
>if 'Windows' in os.environ['OS']...
>to prove it, but now I need to properly support different environments.
>To do so I must accurately determine what system the python instance is
>running on (linux, win, mac, etc).
>Is there a best practises way to do this?
>TIA
>Ian
>
I would do this:
--------------------
if os.name == ''posix':
linuxStuff()
elif os.name == 'nt':
windowsStuff()
elif os.name == 'os2': ...
-------------------
os.name is 'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos'
>
-N
Bearing in mind, of course, that Mac will return "posix", too. And
Cygwin might. Erg.

Best,
James
Dec 14 '06 #8

Post your reply

Help answer this question



Didn't find the answer to your Python question?

You can also browse similar questions: Python