473,836 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to determine Operating System in Use?

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
7 23791


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
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
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*****@redlin epy.comwrote in message
news:4u******** *****@mid.indiv idual.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
excellent, ty

<na******@gmail .comwrote in message
news:11******** **************@ 79g2000cws.goog legroups.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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5314
by: lucpustjens | last post by:
Hello, I want te determine the client operating system, because I need to kno the default cookie directory. If there is a way to determine the cooki directory directly, than it is also good. the used OS te determine are: win 95, win 98, win ME, win XP, win NT Thanks for help,
27
6809
by: Kevin A | last post by:
Hi, Is there a way to determine the name and version of the operating system in a portable way? (for Solaris/Linux) Thanks, Kevin
0
10854
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10601
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10260
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9388
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7794
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6981
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5829
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4460
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4023
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.