【发布时间】:2017-11-02 07:46:30
【问题描述】:
我想在我的 python 代码中显示平均温度。
我找到了http://openweathermap.org/,我用他们的 API 编写了以下代码:
import pyowm
api = pyowm.OWM('Your API key')
collectinfo = api.weather_at_place("Gorinchem,nl")
short = collectinfo.get_weather()
temperature = short.get_temperature('celsius')
print(temperature)
然而 tempature 函数显示多个变量,例如
temp':18.72,'temp_max':20.0,'temp_min':17.0,'temp_kf':无
我只想将平均温度写入一个变量,这样我就可以在我的程序中使用它。
经过一番搜索,我找到了以下代码行:
average_temperature(unit='kelvin')
部分
class pyowm.webapi25.historian.Historian(station_history)
文档链接:https://pyowm.readthedocs.io/en/latest/pyowm.webapi25.html#module-pyowm.webapi25.observation
(使用 ctrl + f ,搜索 celsius 最先弹出)
我不知道如何使用该函数来计算平均温度。
任何可以帮助初学者的人:)?
【问题讨论】:
标签: python python-3.x pip weather-api