how to determine Operating System in Use?

I

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
 
N

nanjundi

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': ...
 
P

Paul Watson

Ian said:
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.
 
I

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 said:
Ian said:
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.
 
I

Ian F. Hood

excellent, ty

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': ...
 
J

James Cunningham

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

Bearing in mind, of course, that Mac will return "posix", too. And
Cygwin might. Erg.

Best,
James
 
P

Prateek

also try:

sys.platform

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


James said:
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': ...

Bearing in mind, of course, that Mac will return "posix", too. And
Cygwin might. Erg.

Best,
James
 
P

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
also try:

sys.platform

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


James said:
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': ...

Bearing in mind, of course, that Mac will return "posix", too. And
Cygwin might. Erg.

Best,
James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top