csv.DictReader and unicode

Laszlo Nagy gandalf at shopzeus.com
Mon Apr 7 10:49:59 CEST 2008

This program

fin = codecs.open(fname,"r",encoding="UTF-8")
eader = csv.DictReader(fin)
for values in reader:

results in:

  File "run.py", line 23, in process_file
    for values in reader:
  File "/usr/local/lib/python2.5/csv.py", line 83, in next
    row = self.reader.next()
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in 
position 13: ordinal not in range(128)

As you can see the exception is thrown in csv.py. How it is possible? 
The csv.DictReader should not use ascii codec for anything, because the 
file encoding is UTF-8.

Please help.



More information about the Python-list mailing list