如何使用 Python 识别 Windows 10?

Dee*_*pak 7 python windows python-2.6

import platform 
if platform.release() == 'post2008Server' and platform.version() ==   '6.2.9200':
     print "It's windows 8"
Run Code Online (Sandbox Code Playgroud)

我以前用它来识别 Windows 8。但它在 Windows 10 中返回相同。那么还有其他方法可以识别它吗?

Kev*_*sse 6

使用以下 Python 版本,一切正常。

Python 3.5.1:

>>> import platform
>>> platform.release()
'10'
>>> platform.version()
'10.0.10240'
Run Code Online (Sandbox Code Playgroud)

蟒蛇 2.7.11

>>> import platform
>>> platform.release()
'10'
>>> platform.version()
'10.0.10240'
Run Code Online (Sandbox Code Playgroud)

升级到至少 2.7.x 怎么样?


编辑:正如@Rogalski 所提到的,您可以随时使用管道ver命令,这应该独立于 Python 版本返回以下内容:

>>> import subprocess
>>> subprocess.Popen('ver', shell=True, stdout=subprocess.PIPE).communicate()[0]
'\r\nMicrosoft Windows [Version 10.0.10240]\r\n'
Run Code Online (Sandbox Code Playgroud)