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!news3.google.com!feeder3.cambrium.nl!feeder1.cambrium.nl!feed.tweaknews.nl!62.216.30.27.MISMATCH!newsgate.cistron.nl!xs4all!transit3.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path: <ebgs...@gmail.com>
X-Original-To: python-l...@python.org
Delivered-To: python-l...@bag.python.org
X-Spam-Status: OK 0.003
Date: Tue, 5 Jun 2007 08:14:34 +0900
From: "js " <ebgs...@gmail.com>
To: Matimus <mccre...@gmail.com>
Subject: Re: How do you htmlentities in Python
In-Reply-To: <1180977447.745432.109040@q19g2000prn.googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
References: <mailman.8674.1180963921.32031.python-list@python.org>
	<1180977447.745432.109040@q19g2000prn.googlegroups.com>
Cc: python-l...@python.org
X-BeenThere: python-l...@python.org
X-Mailman-Version: 2.1.9
Precedence: list
List-Id: General discussion list for the Python programming language
	<python-list.python.org>
List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>,
	<mailto:python-list-requ...@python.org?subject=unsubscribe>
List-Archive: <http://mail.python.org/pipermail/python-list>
List-Post: <mailto:python-l...@python.org>
List-Help: <mailto:python-list-requ...@python.org?subject=help>
List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>,
	<mailto:python-list-requ...@python.org?subject=subscribe>
Newsgroups: comp.lang.python
Message-ID: <mailman.8701.1180998881.32031.python-list@python.org>
Lines: 43
NNTP-Posting-Host: 194.109.207.14
X-Trace: 1180998881 news.xs4all.nl 329 [::ffff:194.109.207.14]:49284
X-Complaints-To: abuse@xs4all.nl

 Thanks you Matimus.
That's exactly what I'm looking for!
Easy, clean and customizable.
I love python :)

On 6/5/07, Matimus <mccre...@gmail.com> wrote:
> On Jun 4, 6:31 am, "js " <ebgs...@gmail.com> wrote:
> > Hi list.
> >
> > If I'm not mistaken, in python, there's no standard library to convert
> > html entities, like &amp; or &gt; into their applicable characters.
> >
> > htmlentitydefs provides maps that helps this conversion,
> > but it's not a function so you have to write your own function
> > make use of  htmlentitydefs, probably using regex or something.
> >
> > To me this seemed odd because python is known as
> > 'Batteries Included' language.
> >
> > So my questions are
> > 1. Why doesn't python have/need entity encoding/decoding?
> > 2. Is there any idiom to do entity encode/decode in python?
> >
> > Thank you in advance.
>
> I think this is the standard idiom:
>
> >>> import xml.sax.saxutils as saxutils
> >>> saxutils.escape("&")
> '&amp;'
> >>> saxutils.unescape("&gt;")
> '>'
> >>> saxutils.unescape("A bunch of text with entities: &amp; &gt; &lt;")
> 'A bunch of text with entities: & > <'
>
> Notice there is an optional parameter (a dict) that can be used to
> define additional entities as well.
>
> Matt
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

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