views:

44

answers:

1

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.

A: 

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
ars
For some reason python doesn't seem to like your syntax.
Anteater7171
The only thing missing was "import wmi" which I've added -- I assumed that was already in your code posted above. Otherwise, it's copy/pasted straight from a python terminal. If you produce the actual error message here, maybe I can help you figure out what's wrong on your end.
ars