How to get version of Windows?

Mark Hammond mhammond at skippinet.com.au
Thu Dec 12 17:35:23 EST 2002


Eric Brunel wrote:
> Hi all,
> 
> Maybe I'm missing something obvious here, but I searched a lot around and 
> couldn't find anything. I'd like to know the version of Windows I'm running 
> on from a Python program. How can I do that? AFAIK, sys.platform, os.name 
> and related stuff always return the same thing on any Windows flavor.
> 
> To be more precise, what I need to know is the Windows "lineage": 
> Win95/98/Me or WinNT/2k/XP. Any clue on a secure way to do that?

For your and others information, Python 2.3 will have this avilable from 
the core (it comes up too often, and the Python test suite ended up 
wanting it!)

Python 2.3a0 (#29, Dec  6 2002, 09:34:12) [MSC v.1200 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> import sys
 >>> print sys.getwindowsversion.__doc__
getwindowsversion()

Return information about the running version of Windows.
The result is a tuple of (major, minor, build, platform, text)
All elements are numbers, except text which is a string.
Platform may be 0 for win32s, 1 for Windows 9x/ME, 2 for Windows NT/2000/XP

 >>> sys.getwindowsversion()
(5, 0, 2195, 2, 'Service Pack 3')

Mark.




More information about the Python-list mailing list