I am trying to read the columns in a file efficiently using CSV reader. The code is:
import csv
csv.register_dialect('csvrd', delimiter='\t', quoting=csv.QUOTE_NONE)
with open('myfile.txt', 'rb') as f:
reader = csv.reader(f,'csvrd')
a0=[x[0] for x in reader]
a1=[x[1] for x in reader]
I obtain the values in the first column, but a1 is empty. If I write a1 first, then a0 is empty.
I know a simple solution, inserting
reader=[x for x in reader]
But just curious about the reason. When you read an entry from the reader, is it removed?
A sample myfile.txt
c11 c21 c31
c21 c22 c32