0

我正在尝试使用 wunderground python API 提取历史天气数据,但是我反复遇到错误。有人可以帮忙吗:

import requests
def get_precip(gooddate):
urlstart = 'http://api.wunderground.com/api/INSERT_KEY_HERE/history_'
urlend = '/q/Switzerland/Zurich.json'

url = urlstart + str(gooddate) + urlend
data = requests.get(url).json()
for summary in data['history']['dailysummary']:
    print ','.join((gooddate,summary['date']['year'],summary['date']['mon'],summary['date']['mday'],summary['precipm'], summary['maxtempm'], summary['meantempm'],summary['mintempm']))

错误:

  File "<ipython-input-49-802c58ba5307>", line 9
    print ','.join((gooddate,summary['date']['year'],summary['date']['mon'],summary['date']['mday'],summary['precipm'],'maxtempm',summary['meantempm'],summary['mintempm']))
            ^
SyntaxError: invalid syntax
4

1 回答 1

3

如果您使用的是 Python 3,则 print 是一个函数,而不是语句,并且需要括号。

print(','.join((gooddate,summary['date']['year'],summary['date']['mon'],summary['date']['mday'],summary['precipm'], summary['maxtempm'], summary['meantempm'],summary['mintempm'])))
于 2015-12-20T16:53:49.370 回答