Unicode problem
Alex Martelli
aleax at mac.com
Sat Jul 7 14:30:30 EDT 2007
pabloski at giochinternet.com <pabloski at giochinternet.com> wrote:
...
Ah, I answered you on the Italian NG before seeing you had also posted
the same request here. What I proposed there was (untested):
import codecs
_rimedi = { u'\x2019': "'" }
def rimedia(exc):
if isinstance(exc, (UnicodeEncodeError, UnicodeTranslateError)):
erore = exc.object[exc.start:exc.end]
if len(erore)==1 and erore in _rimedi: return _rimedi[erore]
raise exc
codecs.register_error('rimedia', rimedia)
outf = codecs.open('filename.txt', 'w', 'iso-8859-15', errors='rimedia')
Alex
More information about the Python-list
mailing list