英文:
Target item in python library
问题
我正在尝试使用psutil在我的树莓派上使用Python仅打印输出中的当前温度。对于修改后的输入的任何帮助将不胜感激。
输入
import psutil
print(psutil.sensors_temperatures())
输出
{'cpu_thermal': [shwtemp(label='', current=36.998, high=None, critical=None)]}
我已经尝试了几种修改输入语句的方法,但没有得到所需的输出:
psutil.sensors_temperatures().current
psutil.sensors_temperatures().cpu_thermal.current
英文:
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
答案1
得分: 0
你来自另一种编程语言。 Python 有所不同:
psutil.sensors_temperatures()
返回一个字典,可以使用语法 dict["key"]
访问。尝试一下:
import psutil
print(psutil.sensors_temperatures()["cpu_thermal"].current)
有关 Python 字典的更多信息,请参阅:https://www.w3schools.com/python/python_dictionaries.asp
英文:
You came from another programming language. Python is different:
psutil.sensors_temperatures()
Returns a dictionary, which is accessed with the syntax dict["key"]
. Try this:
import psutil
print(psutil.sensors_temperatures()["cpu_thermal"].current)
For more on Python's dicts see: https://www.w3schools.com/python/python_dictionaries.asp
答案2
得分: 0
# 获取温度
cpu_temp = psutil.sensors_temperatures()["cpu_thermal"][0]
print(cpu_temp.current)
英文:
# get the temperature
cpu_temp = psutil.sensors_temperatures()["cpu_thermal"][0]
print(cpu_temp.current)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论