Reputation: 14865
I have a .csv file i need to loop over, and then inside a loop, i want to check the value of the next line every iteration. I can't seem to get it to work properly, as it skips the line i was looking ahead in the next iteration.
import csv
file_object = open('file.csv', 'r')
reader = csv.reader(file_object, delimiter = ';')
for line in reader:
next_line = reader.next()
# It now reads the next line and doesn't iterate over it again in the next
# iteration. However, i want it to still iterate over it in the next iteration.
Thank you very much!
Upvotes: 0
Views: 195
Reputation: 775
You could keep track of both the current and the next line "manually:"
line = reader.next()
for next_line in reader:
# Do your processing
line = next_line
# Now do whatever needs to be done with the very last line
Upvotes: 1