所以我随身带着这个JSON字符串
`{'nvme': [shwtemp(label='Composite', current=45.85, high=79.85, critical=84.85)],
'pch_cannonlake': [shwtemp(label='', current=62.0, high=None, critical=None)],
'iwlwifi_1': [shwtemp(label='', current=51.0, high=None, critical=None)],
'coretemp': [shwtemp(label='Package id 0', current=55.0, high=100.0, critical=100.0),
shwtemp(label='Core 0', current=55.0, high=100.0, critical=100.0),
shwtemp(label='Core 1', current=53.0, high=100.0, critical=100.0),
shwtemp(label='Core 2', current=53.0, high=100.0, critical=100.0),
shwtemp(label='Core 3', current=51.0, high=100.0, critical=100.0)]}`
我正在使用Python从这个字符串中读取值。那么如何访问这个JSON中的shwtemp()和“label”
我已经尝试过varName['nvme']['shwtemp']
,但显示错误
现在我从psutil.sensors_temperatures()获得了这个“JSON”
我想做的是在Ubuntu 20.04中获得python中的CPU临时值。所以任何改进都可能是巨大的
您有一个包含一个或多个
shwtemp
的列表,您应该使用索引[0]
来获取第一个元素或for
-loop来分别处理每个元素稍后您将看到对象
shwtemp
,它具有字段.current
显示
coretemp
的最小工作示例(该示例具有更多值,因此for
-loop似乎很有用)结果:
相关问题 更多 >
编程相关推荐