import pyowm
import datetime
import csv
W = pyowm.OWM("****************************")
myHouse = W.weather_at_place("St. albert,Canada")
myWeather = myHouse.get_weather()
wind = myWeather.get_wind()
windspeed = wind["speed"]
windangle = wind["deg"]
humidity = myWeather.get_humidity()
temperature = myWeather.get_temperature("celsius")
high = temperature["temp_max"]
low = temperature["temp_min"]
current = temperature["temp"]
date = datetime.datetime.now().strftime("%D")
time = datetime.datetime.now().strftime("%H")
done=0
while True:
if datetime.datetime.now().strftime("%S") == "00" and done == 0:
done=1
csvfile = open("weatherCSV.csv", "w")
writeCSV = csv.writer(csvfile, delimiter=",")
myWeather = myHouse.get_weather()
wind = myWeather.get_wind
windspeed = wind["speed"]
windangle = wind["deg"]
humidity = myWeather.get_humidity()
temperature = myWeather.get_temperature("celsius")
high = temperature["temp_max"]
low = temperature["temp_min"]
current = temperature["temp"]
date = datetime.datetime.now().strftime("%D")
time = datetime.datetime.now().strftime("%H")
writeCSV.writerow([current,high,low,windspeed,windangle,humidity,date,time])
csvfile.close()
print("Added to file")
if datetime.datetime.now().strftime("%S") == "30" and done == 1:
done=0
this is my program, it should be fine since wind is a dictionnary and temperature works just fine but i get error:はPythonでプログラムを作ったが、TypeError例外を取得:「メソッド」オブジェクトが
...$ python weather.py
Traceback (most recent call last):
File "weather.py", line 29, in <module>
windspeed = wind["speed"]
TypeError: 'method' object is not subscriptable
by the way line 29 is:
windspeed = wind["speed"]
inside the while True: and the if ... : loops. I would very much like to know why this doesn't work and how to make it work because it seems to be running that code just fine the first time, outside the loops. this is running on python 3.6.1 on the latest MacOs.
オブジェクト内の変数を呼び出していると考えている理解していない可能がある)(欠けています。 – Evert