如何使用Python识别windows10?

2024-09-30 12:24:30 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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


Tags: and方法importreleaseifversionwindowsit
1条回答
网友
1楼 · 发布于 2024-09-30 12:24:30

在下面的Python版本中,一切正常。在

Python 3.5.1:

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

Python 2.7.11

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

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


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

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

相关问题 更多 >

    热门问题