Python pyowm库平均温度

Python pyowm库平均温度,python,string,char,openweathermap,Python,String,Char,Openweathermap,我有以下代码: import tkinter as tk import time import pyowm class App(): def __init__(self): self.root = tk.Tk() self.root.attributes("-fullscreen", True) self.label = tk.Label(text="") self.weatherlabel = tk.Label(text

我有以下代码:

import tkinter as tk
import time
import pyowm

class App():
    def __init__(self):
        self.root = tk.Tk()
        self.root.attributes("-fullscreen", True)
        self.label = tk.Label(text="")
        self.weatherlabel = tk.Label(text="")
        self.label.pack()
        self.update_clock()
        self.root.mainloop()

    def update_clock(self):
        now = time.strftime("%H:%M:%S")
        owm = pyowm.OWM()
        owm = pyowm.OWM('*censored*')
        observation = owm.weather_at_place('Modiin,il')
        test = owm.weather_at_place('Modiin,il').get_weather().get_temperature('celsius')
        print(test)
        self.label.configure(text=now,font=("Helvetica",40),fg="white",bg="black")
        self.weatherlabel.configure(text= test,font=("Helvetica",40),fg="white",bg="black")
        self.root.configure(background='black')
        self.root.after(1000, self.update_clock)
        self.label.place(x=1310,y=10)
        self.weatherlabel.place(x=400,y=400)

app = App()
有没有一种方法可以分别请求平均温度、最大温度和最小温度,而不是它提供的巨大字符串?这里的输出是
{'temp':30.48,'temp_max':31.0,'temp_min':30.0,'temp_kf':None}

我知道test[x]可以用字符串的方式对每个字符进行寻址,但这是不可靠的,除非我添加了很多参数来检测每个段中是一位数字还是两位数字。我想要一个更简单的解决方案


感谢您的帮助

这似乎是一本词典,您是否尝试过这样显示结果

dict = {'temp': 30.48, 'temp_max': 31.0, 'temp_min': 30.0, 'temp_kf': None}

print dict['temp']
print "Maximum temperature : {}".format(dict['temp_max'])
输出:

30.48
Maximum temperature : 31.0
如果结果在
test
变量中,则可以执行以下操作:

def update_clock(self):
    now = time.strftime("%H:%M:%S")
    owm = pyowm.OWM()
    owm = pyowm.OWM('*censored*')
    observation = owm.weather_at_place('Modiin,il')
    test = owm.weather_at_place('Modiin,il').get_weather().get_temperature('celsius')
    print "Average temperature : {}".format(test['temp'])
    print "Minimum temperature : {}".format(test['temp_min'])
    print "Maximum temperature : {}".format(test['temp_max'])
    self.label.configure(text=now,font=("Helvetica",40),fg="white",bg="black")
    self.weatherlabel.configure(text= test,font=("Helvetica",40),fg="white",bg="black")
    self.root.configure(background='black')
    self.root.after(1000, self.update_clock)
    self.label.place(x=1310,y=10)
    self.weatherlabel.place(x=400,y=400)

那不是元组,是字典。