codec for html/xml entities!?
Stefan Behnel
stefan_ml at behnel.de
Fri Apr 18 03:24:07 EDT 2008
Martin Bless wrote:
> What's a good way to encode and decode those entities like € or
> € ?
Hmm, since you provide code, I'm not quite sure what your actual question is.
So I'll just comment on the code here.
> def entity2uc(entity):
> """Convert entity like { to unichr.
>
> Return (result,True) on success or (input string, False)
> otherwise. Example:
> entity2cp('€') -> (u'\u20ac',True)
> entity2cp('€') -> (u'\u20ac',True)
> entity2cp('€') -> (u'\u20ac',True)
> entity2cp('&foobar;') -> ('&foobar;',False)
> """
Is there a reason why you return a tuple instead of just returning the
converted result and raising an exception if the conversion fails?
Stefan
More information about the Python-list
mailing list