开发者

"list index out of range"

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&g开发者_JAVA技巧t;
IndexError: list index out of range

This is in windows 7 , btw.


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:

In [18]: import wmi

In [19]: w = wmi.WMI(namespace='root\\wmi')

In [20]: ti = w.MSAcpi_ThermalZoneTemperature()[0]  # first probe

In [21]: ti.CurrentTemperature
Out[21]: 3242
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜