I thought you meant that you wanted to read the rest of the CSV later in the same script.
I see now that you just want to read the "new" stuff each time it runs. Yes, you'd have to keep state somewhere like the file offset or the number of lines previously read.
This partial solution can have problems if it crashes or is run simultaneously (no locking, no error checking, etc.)
I see now that you just want to read the "new" stuff each time it runs. Yes, you'd have to keep state somewhere like the file offset or the number of lines previously read.
This partial solution can have problems if it crashes or is run simultaneously (no locking, no error checking, etc.)
csv_filename = "my.csv" csv_read_counter_file = "csv_last_read" with open(csv_read_counter_file, "r") as f: try: 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))