Aug-11-2022, 03:59 AM
(Aug-11-2022, 12:27 AM)Pedroski55 Wrote: But, if you try to use csv_reader again, it's gone!
That's the way file objects work. Unless you do special handling, the read pointer moves forward in file as you consume it and stops at the end. If you keep reading, it doesn't magically loop back to the front of the file. You're expected to either reopen the file or seek to the front of the file if you want to read it again.
import csv f = open("time.csv") r = csv.reader(f) for line in r: print(line) # lets re-read the file. f.seek(0) for line in r: print(line)But reading a file (I/O) is expensive. Better to avoid repeating it. Either try to do everything in one pass, or as you're already doing (if the file is small enough), read it into memory and operate on the copy in memory.