I'm trying to read in a csv file using the csv library. I'm attempting to iterate through each line but convert to upper case before I attempt some useful function with each line.
import csv
reader = csv.DictReader(open('sample.csv', 'rb'))
for line in reader:
line = line.upper()
name = line['Name']
The above code doesn't appear to work. It fails when I attempt to convert the line read in to upper. I can change each column of the csv file read in to upper individually (using dictionary key) but I want to avoid that since there are lots of keys in the dictionary.
csv.DictReaderobject, which returns adictas you iterate over it instead of atuple, which is whatcsv.readerreturns. Neitherdictnortuplehas an.uppermethod. You probably want to call.upperon one of the contents of thatdict.