Python - Understaning CSV Module and line_num object -


in code, able print line number if error found during processing (called in piece of code), i'm having trouble doing using line_num object. here code .csv 4 rows long:

with open(infile, 'u') infh:     csvreader = csv.reader(infh, delimiter = ',')     header = csvreader.__next__()     linenum = csvreader.line_num      row in csvreader:         print(linenum) 

when execute code, see in console:

1 1 1 1 

my expectation see:

1 2 3 4 

it looks code printing index , not line number...

linenum not changed after first assignment. printing inside loop print same value repeatedly.

why don't print csvreader.line_num follow?

for row in csvreader:     print(csvreader.line_num) 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -