有没有Python2模块比sys模块有更准确的WindowsOS信息?

Is there a Python2 module that has more accurate Windows OS information than the sys module?

以下代码将根据您使用的 python 版本在相同的 Windows 10 OS 上生成不同的值:

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

在 Windows 10 机器上,在 python2 中:major == 6(这不是正确的值

在 Windows 10 机器上,在 python3 中:major == 10(正确值

我很不幸需要在这里使用 python2,但它返回的值不准确。 python2 中是否有一个模块可以为我提供 windows 版本信息的准确值?

Python 2:

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

Python 3:

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

除此之外,与 sys.getwindowsversion 不同,您还可以 运行 在 Linux:

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

还有 platform.version(),它只为您提供没有 OS 名称的版本。