【发布时间】:2014-02-07 23:27:08
【问题描述】:
我有以下定义的函数,并试图弄清楚如何从 csv 中提取值并将它们放入 URL 的“theid”部分。
def get_csv_column(csv_fname, col, **kwargs):
with open(csv_fname, 'rb') as inf:
incsv = csv.reader(inf, **kwargs)
column = [row[col] for row in incsv]
return column
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)
return movdata
###I thought this loop below could reach in, pull the data and add a 5 second delay after each request
with open('step3_desired_output.txt','w') as step3:
for column in withid:
step3.write(movdata)
time.sleep(5)
这似乎不起作用,我不知道如何继续。
【问题讨论】: