SO here's the code -
import csv
with open('csv_example_files.csv') as csvfile:
readCSV = csv.reader(csvfile , delimiter = ',')
print(readCSV)
for row in readCSV:
print(row)
And the output is:
<_csv.reader object at 0x0000024D3DC42388>
['1/2/2014', '4', 'red']
['1/2/2014', '1', 'kv']
['1/2/2014', '1', 'jblock']
['1/3/2018', '1', 'kv']
['1/5/2114', '1', 'kv']
[]
[]
[]
I didn't expect the last 3 empty lists I don't know why they occurred so help me out. I am just a beginner and as I was following a tutorial series and I got stuck here.
csv_example_files.csv
file you're testing with. Also, in Python 3 you should add anewline=''
keyword argument to theopen()
call. For Python 2, you need to add a mode argument after the file name argument of'rb'
.if len(row) == 3:
before your print statement to skip over them.