2024-09-30 12:24:30 发布
网友
import platform if platform.release() == 'post2008Server' and platform.version() == '6.2.9200': print "It's windows 8"
我以前用过这个来识别Windows8。 但对于Windows10,返回的结果是一样的。那么有没有其他的方法来识别它呢?在
在下面的Python版本中,一切正常。在
Python 3.5.1:
>>> import platform >>> platform.release() '10' >>> platform.version() '10.0.10240'
Python 2.7.11
升级到至少2.7.x怎么样?在
Edit:正如@Rogalski所提到的,您可以始终通过管道发送ver命令,这将独立于Python版本返回以下内容:
ver
>>> import subprocess >>> subprocess.Popen('ver', shell=True, stdout=subprocess.PIPE).communicate()[0] '\r\nMicrosoft Windows [Version 10.0.10240]\r\n'
在下面的Python版本中,一切正常。在
Python 3.5.1:
Python 2.7.11
升级到至少2.7.x怎么样?在
Edit:正如@Rogalski所提到的,您可以始终通过管道发送
ver
命令,这将独立于Python版本返回以下内容:相关问题 更多 >
编程相关推荐