Get OS name

A.B., Khalid abkhd at earth.co.jp
Fri Apr 15 15:44:11 EDT 2005


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




More information about the Python-list mailing list