Message from discussion
How do you htmlentities in Python
Path: g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.insightbb.com!news.insightbb.com.POSTED!not-for-mail
NNTP-Posting-Date: Mon, 04 Jun 2007 11:08:03 -0500
Newsgroups: comp.lang.python
Subject: Re: How do you htmlentities in Python
References: <mailman.8674.1180963921.32031.python-list@python.org> <1180965792.757685.132580@q75g2000hsh.googlegroups.com>
X-Newsreader: trn 4.0-test76 (Apr 2, 2001)
From: cla...@lairds.us (Cameron Laird)
Originator: cla...@lairds.us (Cameron Laird)
Date: Mon, 4 Jun 2007 15:41:37 +0000
Message-ID: <heodj4-o3d.ln1@lairds.us>
Lines: 15
NNTP-Posting-Host: 74.132.196.196
X-Trace: sv3-fUoCKIe40atCNU51Yov0xpOl7uipxQqt2JqNp8xAD/zCyhnvoLSmOC/QXWLUU/qaB2JcEJnBHNajhlI!lgY5Fi7UofG1xCJ6bPWXbmEAIMiDOvjkh9AYMJdwg7mVrLrow9HII+SLnk+YUlLdMg==
X-Complaints-To: abuse@insightbb.com
X-DMCA-Complaints-To: ab...@insightbb.com
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.34
In article <1180965792.757685.132...@q75g2000hsh.googlegroups.com>,
Adam Atlas <a...@atlas.st> 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[m.group(1)], 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?