user10669168
user10669168

Reputation:

how to wait for data then print all at once?

so im using WMI and Open Hardware Monitor to get my CPU and GPU temperatures.

the code

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)

how would i make it so it waits for sensor.Name and sensor.Value and then prints it all at once, instead of printing it as it gets the data?

Upvotes: 1

Views: 139

Answers (1)

Mayank Porwal
Mayank Porwal

Reputation: 34086

Try:

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

Upvotes: 1

Related Questions