“列表索引超出范围”
下面我有以下代码,应该获取 CPU 温度。
import wmi
w = wmi.WMI()
print w.Win32_TemperatureProbe()[0].CurrentReading
然而,当我运行它时,我收到以下警告:
Traceback (most recent call last):
File "<string>", line 244, in run_nodebug
File "<module1>", line 3, in <module>
IndexError: list index out of range
顺便说一句,这是在 Windows 7 中。
Below I have the following code that is supposed to get the CPU temperature.
import wmi
w = wmi.WMI()
print w.Win32_TemperatureProbe()[0].CurrentReading
When I run it I get the following warning however:
Traceback (most recent call last):
File "<string>", line 244, in run_nodebug
File "<module1>", line 3, in <module>
IndexError: list index out of range
This is in windows 7 , btw.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这仅意味着您的计算机(可能是您的硬件供应商)上未实现TemperatureProbe。
您的另一个选择是连接到 root\WMI 命名空间并查询“select * from MSAcpi_ThermalZoneTemperature”,这将返回探测器,您可以查询以十分之一开尔文为单位的当前温度。 python的WMI中应该有类似的API。
更新:这里有一些有效的代码:
This just means that TemperatureProbe isn't implemented on your machine (probably your hardware vendor).
Your other option is to connect to the root\WMI namespace and query "select * from MSAcpi_ThermalZoneTemperature" which will return the probes and you can query for current temperature in tenths of kelvins. There should be a similar API in python's WMI.
UPDATE: here's some code that works: