I need an example code for accessing CPU temperature in python.
I'm running windows 7, BTW.
I need an example code for accessing CPU temperature in python.
I'm running windows 7, BTW.
Check out the cputemp library.
EDIT: on windows, you might be able to convert this IronPython script which uses WMI using the python WMI library.
You can use pywin32 to access the native Windows API. I believe it should be possible to query the Windows API for the CPU temperature if the manufacturer for your mainboard driver registers a WMI Data Provider through their driver. Assuming this is the case you could download the pywin32 extensions and the Python WMI module mentioned in the answer by ars, and then proceed as follows:
import wmi
w = wmi.WMI()
print w.Win32_TemperatureProbe()[0].CurrentReading
Looking at the IronPython script in the ars' answer there seems to be another way to do it too, using a different WMI object. Using the same API and approach you could try receiving the temperature value with
w = wmi.WMI(namespace="root\wmi")
temperature_info = w.MSAcpi_ThermalZoneTemperature()[0]
print temperature_info.CurrentTemperature
which apparently should return the temperature value in tenths of Kelvin, thus to receive the degree in Celsius I guess you just divide this value by 10 and subtract ~273.