如何使用Python识别windows 10?

如何使用Python识别windows 10?,python,windows,python-2.6,Python,Windows,Python 2.6,我以前用过这个来识别Windows8。 但在Windows10中,它返回相同的结果。那么有没有其他方法来识别它呢?在以下Python版本中,一切正常 Python 3.5.1: import platform if platform.release() == 'post2008Server' and platform.version() == '6.2.9200': print "It's windows 8" Python 2.7.11 >>> import

我以前用过这个来识别Windows8。
但在Windows10中,它返回相同的结果。那么有没有其他方法来识别它呢?

在以下Python版本中,一切正常

Python 3.5.1:

import platform 
if platform.release() == 'post2008Server' and platform.version() ==   '6.2.9200':
     print "It's windows 8"
Python 2.7.11

>>> import platform
>>> platform.release()
'10'
>>> platform.version()
'10.0.10240'
升级到至少2.7.x怎么样


编辑:正如@Rogalski所提到的,您始终可以通过管道传递
ver
命令,这将返回以下独立于Python版本的内容:

>>> import platform
>>> platform.release()
'10'
>>> platform.version()
'10.0.10240'

我这里没有Windows 10自动取款机,你能检查一下吗?如果一切都失败了,你可以使用
子进程调用
systeminfo
可执行文件,解析它提供给你的信息。不能重新编程;我从
version()
win32\u ver()
中得到
10.0.10586
注意,Python 2.6实际上在2013年结束了支持,因此很可能是Python 2.6根本不支持这里的细粒度Windows版本检测。你应该考虑升级到Python 2.7(它应该是无痛的),甚至是当前的Python 3版本(3.5现在)。code>subprocess.Popen('ver',shell=True,stdout=subprocess.PIPE).communicate()[0]
由于某些依赖项,目前我无法切换到2.7,因此我将使用第二个选项。感谢您的帮助。@Deepak,对于GUI应用程序,您可以添加
Popen
选项
creationflags=8
,以避免创建控制台窗口。8是
分离\u进程
标志的值。在这种情况下,Windows不会创建控制台(即conhost.exe)或将其附加到cmd.exe进程。
>>> import subprocess
>>> subprocess.Popen('ver', shell=True, stdout=subprocess.PIPE).communicate()[0]
'\r\nMicrosoft Windows [Version 10.0.10240]\r\n'