python - AttributeError:模块“os”没有属性“uname”
问题描述
当我做:
>>> import os
>>> os.uname()
我收到如下所示的属性错误:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
os.uname()
AttributeError: module 'os' has no attribute 'uname'
我该如何解决这是我的 python 损坏或其他原因,因为在文档中。提前谢谢你。
解决方案
我在 Windows 10 上的 IDLE 中以完全相同的方式运行您的代码并得到了相同的结果。
>>> print(os.uname())
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
print(os.uname())
AttributeError: module 'os' has no attribute 'uname'
正如@Joran Beasley 指出的那样,此功能仅在某些操作系统中可用。
来自在线编译器:
posix.uname_result(sysname='Linux', nodename='Check', release='5.4.10-x86_64-linode132', version='#1 SMP PREEMPT Thu Jan 9 21:17:12 UTC 2020', machine='x86_64')
如果你想获得当前的操作系统,我推荐这个platform
模块。
>>> import platform
>>> platform.platform()
'Windows-10-10.0.18362-SP0'
有些人更喜欢使用os
模块,但platform
更具可读性。
推荐阅读
- php - Symfony 1.4 sfMailer:配置 TLS 自签名
- python - 将字符串转换为相同字符串的值
- c# - WPF 中的阴影覆盖其他控件
- bash - 合计并平均每个相同字符串旁边的数字
- python-3.x - 在对象高度和宽度上裁剪二进制图像
- r - RSelenium 与 Docker。checkError(res) 中的错误
- javascript - 带有 React Native 的 Magento 2 REST API
- java - 即使我所有的 XML 文件都没有错误,也不会生成 R.java
- redirect - IIS 7.5 - 从一个域重定向到另一个域,同时保持路径
- jmeter - Jmeter > File Upload > Amazon:录制脚本时无法在我们的应用程序中上传文件