Python:系统平台不正确的结果

2024-09-28 22:26:19 发布

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

我在ubuntu13.10下使用pythonshell。我的Linux内核版本是“3.11.0-13-generic”。那么为什么要用Python变量“系统平台“存储值”Linux2“而不是“Linux3”?在

enter image description here


Tags: 版本linux系统平台内核genericlinux2pythonshell
3条回答

因为sys.platform不是内核版本。它是编译时添加到python二进制文件或库中的字符串。在linux上它总是linux2,除了python3.3之后,它变成了linux。在

Possible values from sys.platform?

来自the docs

Changed in version 2.7.3: Since lots of code check for sys.platform == 'linux2', and there is no essential change between Linux 2.x and 3.x, sys.platform is always set to 'linux2', even on Linux 3.x.

根据documentation

sys.platform is always set to 'linux2', even on Linux 3.x. In Python 3.3 and later, the value will always be set to 'linux', so it is recommended to always use the startswith idiom presented above.

相关问题 更多 >