I have a csv DictReader object (using Python 3.1), but I would like to know the number of lines/rows contained in the reader before I iterate through it. Something like as follows...
myreader = csv.DictReader(open('myFile.csv', newline=''))
totalrows = ?
rowcount = 0
for row in myreader:
print("Row %d/%d" % (rowcount,totalrows))
totalrows = len(open('myFile.csv').readlines())
rows = list(myreader) totalrows = len(rows) for i, row in enumerate(rows): print("Row %d/%d" % (i+1, totalrows))