By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,595 Members | 1,404 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,595 IT Pros & Developers. It's quick & easy.

Get OS name

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

Jul 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
rbt
codecraig wrote:
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 ;)
Jul 19 '05 #2

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

Jul 19 '05 #3

P: n/a
"codecraig" wrote:
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:
python
import platform
print platform.system(), platform.release() Windows XP

$ python import platform
print platform.system(), platform.release()

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

Jul 19 '05 #4

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

Jul 19 '05 #5

P: n/a
codecraig wrote:
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.
import platform
print platform.system(), platform.release() Windows 98
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. import platform
print platform.system(), platform.release() Windows


Regards,
Khalid

Jul 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.