Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion How do you htmlentities in Python

View parsed - Show only message text

Path: g2news1.google.com!news2.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 12:08:00 -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 16:54:53 +0000
Message-ID: <tnsdj4-hnf.ln1@lairds.us>
Lines: 23
NNTP-Posting-Host: 74.132.196.196
X-Trace: sv3-5Ls3l32VkGBhLUIYzhN9nO1rFOVIJT9NZlyimz7+2RAlwXnyEAxZyP7aW10AGLY2gEPPM5pHIHIIt9r!rkWlEE3N3Nyy/RW/XMTciHQyK7+BN5QxkyoYOjaIIuQLSJ6At7SJClO2UjEoaHbViQ==
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)
>

A.  I *think* you meant
        import re
        from htmlentitydefs import name2codepoint
        def htmlentitydecode(s):
            return re.sub('&(%s);' % '|'.join(name2codepoint), lambda m: chr(name2codepoint[m.group(1)]), s)
    We're stretching the limits of what's comfortable
    for me as a one-liner.
B.  How's it happen this isn't in the Cookbook?  I'm
    curious about what other Pythoneers think:  is 
    this better memorialized in the Cookbook or the
    Wiki?

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google