Fredrik Lundh wrote:

> [...]
> if you want more control of the replacement, you can skip the translate
> step and use your own error handler, e.g.
> 
>     charmap = ... see above ...
> 
>     def fixunicode(info):
>         s = info.object[info.start:info.end]
>         try:
>             return charmap[ord(s)], info.end

This will fail if there's more than one consecutive unencodable 
character, better use
    return charmap[ord(s[0])], info.start+1
or
    return "".join(charmap.get(ord(c), u"<U+%04x>" % ord(c)) for c in 
s), info.end
(without the try:) instead.

Bye,
    Walter Dörwald
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to