Get OS name

C

codecraig

How can I get the OS Name, such as "Windows XP Pro". I know I can do

sys.getwindowsversion but that doesnt return a nice Windows XP Pro
string.

and os.name gives "nt"

thanks.
 
R

rbt

codecraig said:
How can I get the OS Name, such as "Windows XP Pro". I know I can do

sys.getwindowsversion but that doesnt return a nice Windows XP Pro
string.

and os.name gives "nt"

thanks.

Read the docs... sys.getwindowsversion() should do the trick. AFAIK,
there is no way to differentiate between XP Home and Pro unless you
attempt to call an executable that's only available on Pro... such as
"systeminfo". If that call fails, it's reasonably safe to assume that
you're on a XP Home machine... especially if getwindowsversion()
produces a major of 5 and a minor of 1

As everyone knows that XP is really just NT 5.1 ;)
 
C

codecraig

i guess i wanted the result in a nice string like Windows XP instead of
5.1

i guess i'll have to convert it myself, thanks
 
F

Fredrik Lundh

codecraig said:
How can I get the OS Name, such as "Windows XP Pro"
i guess i wanted the result in a nice string like Windows XP instead of
5.1

i guess i'll have to convert it myself, thanks

your requirements keep changing. to get the OS name in a platform-
independent way, use the platform module:
Windows XP

$ pythonLinux 2.4.18-3

etc.

(tip: reading the "library reference" table of contents a couple of times is a great way
to learn about the contents of the standard library. http://docs.python.org/lib/lib.html )

</F>
 
C

codecraig

my requirements for getting the OS info havent changed. My first
message says "How can I get the OS Name, such as "Windows XP Pro"."
.....that's what I wanted all along.

thanks for the information anyway, i believe platform is better than my
previous approach.

thanks
 
A

A.B., Khalid

codecraig said:
my requirements for getting the OS info havent changed. My first
message says "How can I get the OS Name, such as "Windows XP Pro"."
....that's what I wanted all along.

thanks for the information anyway, i believe platform is better than my
previous approach.

thanks



Please note that platform appears to require win32api to be in your
system. The following is the code from \Lib\platform.py.

The function that gets the data sets these values as default

[Code from platform.py]
def win32_ver(release='',version='',csd='',ptype=''):
[/Code]

And will return empty strings in case win32api is not found:

[Code from platform.py]
# Import the needed APIs
try:
import win32api
except ImportError:
return release,version,csd,ptype
[/Code from platform.py]


Accordingly, my Python 2.3.5 final which has win32api installed can get
the platform answer right:

$ /py23/python/dist/src/MinGW/python -i
Python 2.3.5 (#62, Feb 12 2005, 02:56:20)
[GCC 3.4.2 (mingw-special)] on win32
Type "help", "copyright", "credits" or "license" for more information.


But where I don't have win32api installed, my Python does not know that
answer you seek:


$ /py25/python/dist/src/MinGW/python -i
Python 2.5a0 (#65, Apr 12 2005, 20:22:54)
[GCC 3.4.2 (mingw-special)] on win32
Type "help", "copyright", "credits" or "license" for more information.


Regards,
Khalid
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top