I am reading a csv file using the csv.DictReader class. I read in the python documentation that class csv.DictReader (csvfile, fieldnames = None, restkey = None, restval = None, dialect = 'excel', * args, ** kwds)
If fieldnames is omitted, the values ββin the first line of csvfile will be used as field names.
I tried to get the first line of my csv file using the dictionary method :()
my_reader = csv.DictReader(src) print(my_reader.keys())
By doing this, I get the following error:
print(my_reader.keys()) AttributeError: 'DictReader' object has no attribute 'keys'
Why?
source share