How do you htmlentities in Python

Adam Atlas adam at
Mon Jun 4 16:03:12 CEST 2007

As far as I know, there isn't a standard idiom to do this, but it's
still a one-liner. Untested, but I think this should work:

import re
from htmlentitydefs import name2codepoint
def htmlentitydecode(s):
    return re.sub('&(%s);' % '|'.join(name2codepoint), lambda m:
name2codepoint[], s)

More information about the Python-list mailing list