使用 Python 获取当前的 Windows 11 版本

Ped*_*dro 3 python windows-11

在 Python 3.8.10 中,我无法获得正确的 Windows 版本,我正在运行 Windows 11 Insider Preview,但输出显示为 Windows 10

漏洞

有什么解决方法吗?

编辑:目前我发现检测 W11 的唯一方法是

wmic os get name
Run Code Online (Sandbox Code Playgroud)

Ped*_*dro 5

我使用的解决方案如下:

def is_win11():
    return sys.getwindowsversion().build >= 22000
Run Code Online (Sandbox Code Playgroud)

要了解您拥有哪种类型的 Windows(例如 Entreprise),您可以使用platform.win32_edition().