Python历史天气数据API:wunderground

Python历史天气数据API:wunderground,python,ipython,wunderground,Python,Ipython,Wunderground,我试图使用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

我试图使用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
文件“”,第9行
打印“,”。加入((gooddate、摘要['date']['year']、摘要['date']['mon']、摘要['date']['mday']、摘要['precipm']、'maxtempm',摘要['meantempm']、摘要['mintempm']))
^
SyntaxError:无效语法

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

print(','.join((gooddate,summary['date']['year'],summary['date']['mon'],summary['date']['mday'],summary['precipm'], summary['maxtempm'], summary['meantempm'],summary['mintempm'])))

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

print(','.join((gooddate,summary['date']['year'],summary['date']['mon'],summary['date']['mday'],summary['precipm'], summary['maxtempm'], summary['meantempm'],summary['mintempm'])))