我有一个.csv文件,我需要循环,然后在循环内,我想检查每次迭代的下一行的值。我似乎无法让它正常工作,因为它跳过了我在下一次迭代中向前看的线。
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.
非常感谢!
答案 0 :(得分:1)
您可以“手动:”
跟踪当前和下一行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