PyDocs

Nav

File Formats

DictReader

csv

class (source)
  • DictReader(f, fieldnames=None, restkey=None, restval=None, dialect='excel', *args, **kwds)
Create an object that operates like a regular reader but maps the information in each row to a dict whose keys are given by the optional fieldnames parameter.
Changed in 3.6, 3.8
  • 3.6: Returned rows are now of type OrderedDict.
  • 3.8: Returned rows are now of type dict.
Members of DictReader

f

fieldnames
If not passed as a parameter when creating the object, this attribute is initialized upon first access or when the first record is read from the file.
1 Example
>>> import csv
>>> with open('names.csv', newline='') as csvfile:
...     reader = csv.DictReader(csvfile)
...     for row in reader:
...         print(row['first_name'], row['last_name'])
...
Eric Idle
John Cleese

>>> print(row)
{'first_name': 'John', 'last_name': 'Cleese'}
from the Python docs
See Also
No see-alsos for csv/DictReader
0 Notes
No notes for DictReader