Python 的平台模块未检测到 Windows 10 [英] Python's platform module does not detect windows 10

查看:31
本文介绍了Python 的平台模块未检测到 Windows 10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 Windows 10,如果平台是 Windows 10,则需要添加一些代码.因此,我查看了 python 文档并阅读了有关平台模块的信息.这是文档所说的:

<块引用>

platform.win32_ver(release='', version='', csd='', ptype=''):从 Windows 注册表获取其他版本信息,并返回一个元组(发布、版本、csd、ptype),指的是操作系统版本、版本号、CSD 级别(服务包)和操作系统类型(多/单处理器)

当我在我的 Windows 10 机器上尝试相同的功能时,我得到了以下结果:

<预><代码>>>>platform.win32_ver()('8', '6.2.9200', '', u'Multiprocessor Free')

但是,我期望发布是 10 个而不是 8 个.

所以,知道我在这里遗漏了什么吗?

另外,有人可以告诉我是否有其他方法可以检测 Windows 平台是否为 Windows 10?

解决方案

问题是python使用GetVersionEx来判断版本.

您可以在此处阅读,Microsoft 不再支持此功能并提供不同的 API.

但是,您始终可以自己调用新 API,或检查 HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion 中的注册表值.

您也可以使用 WMI 来获取 Win32_OperatingSystem 实例.

我还想指出,特定版本检查通常被认为是一种不好的做法.

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.

这篇关于Python 的平台模块未检测到 Windows 10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆