Aug-11-2022, 12:27 AM
What I mean is, certain, "Python objects", for instance the result of csv.reader() can only be used 1 time. I just wonder why.
Example:
That was the same with your code in this thread. I didn't put *Nset in the text file, so the whole of file was searched.
After that file was unavailable for the second loop.
I just wonder why that is.
For practical purposes, I read csv_reader into a list, which remains available for as many uses as I want.
Example:
import csv myfile = '/home/pedro/myPython/csv/time.csv' csv_reader = csv.reader(myfile, delimiter=',') for row in csv_reader: print(row)
Output:['time', ' comment']
['2022-04-25 7:06 AM', ' bla ']
['2022-04-25 7:07 AM', ' blabla']
['2022-04-25 7:08 AM', ' ha']
['2022-04-25 7:09 AM', ' haha']
But, if you try to use csv_reader again, it's gone!for row in csv_reader: print(row)You get nothing, csv_reader is "burned" and unavailable. You would have to read it in again.
That was the same with your code in this thread. I didn't put *Nset in the text file, so the whole of file was searched.
After that file was unavailable for the second loop.
I just wonder why that is.
For practical purposes, I read csv_reader into a list, which remains available for as many uses as I want.