因此我使用WMI和Open Hardware Monitor获取我的CPU和GPU温度。
代码
import wmi
w = wmi.WMI(namespace="root\OpenHardwareMonitor")
temperature_infos = w.Sensor()
for sensor in temperature_infos:
if sensor.SensorType==u'Temperature':
print(sensor.Name)
print(sensor.Value)
我将如何使它等待sensor.Name
和sensor.Value
,然后一次全部打印,而不是在获取数据时立即打印呢?
答案 0 :(得分:1)
尝试:
import wmi
w = wmi.WMI(namespace="root\OpenHardwareMonitor")
temperature_infos = w.Sensor()
d = dict() ## Create an empty dictionary
for sensor in temperature_infos:
if sensor.SensorType==u'Temperature':
#print(sensor.Name)
#print(sensor.Value)
d[sensor.Name] = sensor.Value
print(d) # Print the dictionary when the loop is over