Convert from unicode chars to HTML entities
Leif K-Brooks
eurleif at ecritters.biz
Sun Jan 28 23:41:19 EST 2007
Steven D'Aprano wrote:
> I have a string containing Latin-1 characters:
>
> s = u"© and many more..."
>
> I want to convert it to HTML entities:
>
> result =>
> "© and many more..."
>
> Decimal/hex escapes would be acceptable:
> "© and many more..."
> "© and many more..."
>>> s = u"© and many more..."
>>> s.encode('ascii', 'xmlcharrefreplace')
'© and many more...'
More information about the Python-list
mailing list