如何等待数据然后一次全部打印?

时间:2018-11-18 03:19:57

标签: python python-3.x

因此我使用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.Namesensor.Value,然后一次全部打印,而不是在获取数据时立即打印呢?

1 个答案:

答案 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