I'm struggling a bit with two things:
I've got a huge block of stuff to do under
for row in readerthat I'm worried about everything being executed properly. There seems to be some superstition about long instruction blocks, so I'm channeling that, ignorantly.I'm not sure how best to advance to the next record, or even if I have to do so. When I've reached an error condition, the line is written to a discard file, so I can really just wait until the "end" of the loop. But what do I need to do to say "next record, please?" Do I have to make an explicit
next()at the end of thefor row...loop?
Appreciate some guidance here. TC
with open('data.csv',rb) as f:
reader = csv.reader(f)
next(reader, None) # skip the header
for row in reader:
foo
foo
lots more foo
if bar1 == errorvalue1:
writediscard (row)
else:
if bar2 == errorvalue2:
writediscard (row)
else:
writegoodstufftothedatabase(data)
# in all cases, want to advance to the next record
Note that I've def writediscard and writegoodstufftothedatabase above. I can handle writing and committing writes to a sqlitedb. This darn iterating through a CSV is another story.