0

The following code will generate different values, on the same Windows 10 OS, based on what version of python you are using:

import sys
info = sys.getwindowsversion()
major = info.major

On a Windows 10 machine, in python2: major == 6 (which is not the correct value)

On a Windows 10 machine, in python3: major == 10 (the correct value)

I'm in the unfortunate position of needing to use python2 here, but the values it is returning are not accurate. Is there a module, available in python2, that will give me the accurate values for windows version information?

jlents
  • 790
  • 8
  • 20

1 Answers1

1

Python 2:

>>> platform.platform()
'Windows-10-10.0.17134'

Python 3:

>>> platform.platform()
'Windows-10-10.0.17134-SP0'

Besides that, unlike sys.getwindowsversion, you can also run this on Linux:

>>> platform.platform()
'Linux-5.4.0-51-generic-x86_64-with-glibc2.29'

There is also platform.version() which gives you just the version without the OS name.

zvone
  • 18,045
  • 3
  • 49
  • 77