Jaap van Wingerde wrote:
> Stefan Behnel wrote:
>> Omschrijving = Omschrijving.replace("priv?", 'privé')
actually, make that
Omschrijving = Omschrijving.replace(u"priv?", u'privé')
(mind the u"...")
> ....
> import codecs
> file = "postbank.csv"
> output = "%s.eb" % file
> outfile = codecs.open(output, "w", "utf_8")
> Omschrijving = u'priv? assuranti?n' # string from postbank.csv
> Omschrijving = Omschrijving.replace("priv?", 'privé')
> Omschrijving = Omschrijving.replace("Assuranti?n", 'Assurantiën')
I guess you mixed up the case here.
> outfile.write (Omschrijving)
>
> "Traceback (most recent call last):
> File "/home/jaap/Desktop/unicode.py", line 9, in <module>
> outfile.write (Omschrijving)
> File "/usr/lib/python2.5/codecs.py", line 638, in write
> return self.writer.write(data)
> File "/usr/lib/python2.5/codecs.py", line 303, in write
> data, consumed = self.encode(object, self.errors)
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 4:
> ordinal not in range(128)"
Does this help?
outfile = codecs.open(output, "wb", encoding="UTF-8")
(mind the "wb" for 'write binary/bytes')
Looks like you'd be happier with Python 3.0, BTW...
Stefan
--
http://mail.python.org/mailman/listinfo/python-list