csv.DictReader and unicode
Jarek Zgoda
jzgoda at o2.usun.pl
Mon Apr 7 05:00:55 EDT 2008
Laszlo Nagy napisał(a):
> This program
>
> fin = codecs.open(fname,"r",encoding="UTF-8")
> eader = csv.DictReader(fin)
> for values in reader:
> pass
>
> 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.
Reader works with byte strings, not unicode objects.
--
Jarek Zgoda
Skype: jzgoda | GTalk: zgoda at jabber.aster.pl | voice: +48228430101
"We read Knuth so you don't have to." (Tim Peters)
More information about the Python-list
mailing list