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
Post a Comment