Dec-08-2020, 09:30 PM
I meant for the open attempt on the read file to be inside the "try" section. This is a minor change:
I'm sure you could incorporate a range check instead of a simple "index <= lines_read" check. You would just need to determine how you want to populate the range.
csv_filename = "my.csv" csv_read_counter_file = "csv_last_read" try: with open(csv_read_counter_file, "r") as f: lines_read = int(f.readline().rstrip()) except: # On any error, just reset back to start of file. lines_read = 0 with open(csv_filename, "r") as f: for index, line in enumerate(f): if index <= lines_read: continue print(line.rstrip()) with open(csv_read_counter_file, "w") as f: f.write(str(index))I don't know why you would only be getting the first line. It should skip until the lines after that point are read.
I'm sure you could incorporate a range check instead of a simple "index <= lines_read" check. You would just need to determine how you want to populate the range.