Unicode error handler

Walter Dörwald walter at livinglogic.de
Wed Jan 31 11:47:39 EST 2007

Hieu.D.Hoang at gmail.com wrote:
> On Jan 30, 11:28 pm, Walter Dörwald <wal... at livinglogic.de> wrote:
>> codecs.register_error("transliterate", transliterate)
>>    Walter
> Really, really slick solution.
> Though, why was it [:1], not [0]? ;-)

No particular reason, unicodedata.normalize("NFD", ...) should never
return an empty string.

> And one more thing:
>> def transliterate(exc):
>>         if not isinstance(exc, UnicodeEncodeError):
>>                 raise TypeError("don'ty know how to handle %r" % r)
> I don't understand what %r and r are and where they are from. The man
> 3 printf page doesn't have %r formatting.

%r means format the repr() result, and r was supposed to be exc. ;)


More information about the Python-list mailing list