pythonpipsutil

Target item in python library


I am trying to print just the current temperature only from the output using psutil on my raspberry pi with python. Any help in altered inputs would be greatfully appreciated.

Input

Import psutil

print ((psutil.sensors_temperatures())

Output

{'cpu_thermal': [shwtemp(label='', current=36.998, high=None, critical=None)]}

I have tried several alteration to the input statement but not getting the output required

psutil.sensors_temperatures().current

psutil.sensors_temperatures().cpu_thermal.current


Solution

  • # get the temperature
    cpu_temp = psutil.sensors_temperatures()["cpu_thermal"][0]
    print(cpu_temp.current)