Eric V. Smith added the comment:
Steven is correct: your problem is that in the first example you're reading the
header row before you pass the file to DictReader, so the DictReader cannot
know what your columns are named. (Actually, your code uses the second row of
your file as the column n
Steven D'Aprano added the comment:
Can you please provide a *simple* and *complete* demonstration, including the
*full* traceback? As given, we cannot run the supplied code and don't know what
the contents of the csv file are supposed to be.
See here for more detail: http://www.sscce.org/
B
New submission from Eduardo Orochena :
def load_file(filename):
with open(filename, 'r', encoding='utf-8') as fin:
header = fin.readline()
print('Found ' + header)
reader = csv.DictReader(fin)
for row in reader:
print(type(row), row)