Why does platform.release() return “8” in Windows

2019-06-28 03:28发布

This question already has an answer here:

I run this on my Windows 10 workstation:

import platform
print platform.release()
> 8

I'm somewhat perplexed. Should the response not have been "10" as I'm on Windows 10?

1条回答
一纸荒年 Trace。
2楼-- · 2019-06-28 03:39

I did some digging...

An issue was resolved for Python 2.7.10 according to its release notes:

  • Issue #16176: Properly identify Windows 8 via platform.platform()

However, with Windows 10 you still don't get the proper response. For this, a fix was created in late September, 2015: https://hg.python.org/cpython/rev/2f57270374f7

As this was performed after the 2.7.10 release (released in late May, 2015), this will hopefully make it into a future release. Right now it should make it into 2.7.11 which is scheduled for a December 2015 release.

The fix makes platform read the Windows version from kernel32.dll to avoid compatibility issues.

A workaround right now could be to execute the ver command if the system is Windows based, and then parse the response manually.

EDIT:Indeed, this was fixed in Python 2.7.11:

import platform
print platform.release()
> 10
查看更多
登录 后发表回答