Agniswar Bakshi Agniswar Bakshi - 5 months ago 47
Python Question

Python's platform module does not detect windows 10

I am working on Windows 10 presently and need to put some code if the platform is Windows 10. So, I checked in python docs and read about platform module. This is what the documentation says :

platform.win32_ver(release='', version='', csd='', ptype='')
Get additional version information from the Windows Registry and return a tuple (release, version, csd, ptype) referring to OS release, version number, CSD level (service pack) and OS type (multi/single processor)

When I tried the same function on my Windows 10 machine I got below :

>>> platform.win32_ver()
('8', '6.2.9200', '', u'Multiprocessor Free')

But, I was expecting the release to be 10 instead of 8.

So, any idea if I am missing something here ?

Also, can somebody please tell me if there exists any other way to detect if the windows platform is Windows 10 ?


The problem is python uses GetVersionEx to determine the version.

As you can read here, Microsoft doesn't support this anymore and offers a different API.

However, you can always call the new API yourself, or check the registry value at HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion.

You can also use WMI to get the Win32_OperatingSystem instance.

I'd also like to note that specific version checking is generally considered a bad practice.