423,688 Members | 1,894 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,688 IT Pros & Developers. It's quick & easy.

how to determine Operating System in Use?

P: n/a
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


P: n/a


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

P: n/a
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

P: n/a
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" <pw*****@redlinepy.comwrote in message
news:4u*************@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

P: n/a
excellent, ty

<na******@gmail.comwrote in message
news:11**********************@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

P: n/a
On 2006-12-13 19:28:14 -0500, na******@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

P: n/a
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, na******@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

P: n/a
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, na******@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

This discussion thread is closed

Replies have been disabled for this discussion.