How do you htmlentities in Python

Cameron Laird claird at
Mon Jun 4 17:41:37 CEST 2007

In article <1180965792.757685.132580 at>,
Adam Atlas  <adam at> wrote:
>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)

How strange that this doesn't appear in the Cookbook!  I'm
curious about how others think:  does such an item better 
belong in the Cookbook, or the Wiki?

More information about the Python-list mailing list