The following code work fine.
with open(filename, 'rb') as f:
reader = csv.reader(f)
for row in reader:
cur.execute(insertStatement, row)
when I insert these two lines, something goes wrong.
with open(filename, 'rb') as f:
reader = csv.reader(f)
totalrows = len(list(reader))
print totalrows # Print out the correct output
for row in reader:
cur.execute(insertStatement, row)
My guess is that when i assign totalrows = len(list(reader)) the cursor moves to the end of the file there for nothing happens in the for loop.
if this is true how can i move the cursor back to the start without closing the file and reopening it? if not please help.