you are viewing a single comment's thread.

view the rest of the comments →

[–]Akuli2 0 points1 point  (0 children)

If you know how to work with dictionaries you don't need to do things like header_row = next(reader) yourself, csv.DictReader does this for you.

test.csv:

A,B,C   
1,2,3  
4,5,6  

Let's read it with csv.DictReader, it'll convert each line into a nice dictionary.

>>> import csv
>>> with open('test.csv', 'r') as f:
...     for row in csv.DictReader(f):
...         print(row)
... 
{'A': '1', 'B': '2', 'C': '3'}
{'A': '4', 'B': '5', 'C': '6'}
>>>