我試圖從csv文件的第一列中逐步加載值到URL中,並以5秒的延遲一次請求一個URL。在第一列的每個值應替換爲「theid」嘗試延遲運行已定義的函數
這是到目前爲止我的代碼:
# I have a defined function
def withid (theid):
""""""
global cache
dupe = False
theurl = "{0}{1}{2}".format(OMDBURL, "?i=", theid)
response = urllib2.urlopen(theurl)
movdata = json.load(response)
for mov in cache:
if movdata[MKEY[1]] == mov[MKEY[1]]:
dupe = True
if not dupe:
cache.append(movdata)
outfile2 = open('outputrows2-shortened.csv', 'rb')
for row in outfile2:
theid = outfile2(row[0])
time.sleep(5)
輸出:類型錯誤:「文件」對象不是可調用
還有......是什麼問題? – jonrsharpe
它不工作,我只是得到上面的錯誤信息 – kegewe
這是因爲'atid'(now)返回一個字典;你想把它附加到jsonlist,而不是相反。試試'jsonlist.append(withid(row [0]))''。 –