This feels like a very basic question, but I can't find any mention of it elsewhere. I'm a beginning Python user.
When I read in data using DictReader, and then use the dictionary, I'm unable to reference it again. For example, using this code:
#!/usr/bin/python
import csv
import cgi
import cgitb
cgitb.enable()
print "<head><title>Title</title></head><body>"
f = open("blurbs.csv","rb")
blurbs = csv.DictReader(f, delimiter="")
for row in blurbs:
print row
for row in blurbs:
print row
f.close()
print "</body>"
Will only print out the contents of blurbs.csv once. The second "for row in blurbs:" does nothing. Is there something I'm missing? How can I make the dictionary into something I can reference repeatedly?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…