Htmlizing text

Fredrik Lundh fredrik at pythonware.com
Tue Nov 30 09:32:26 CET 1999


Phil Hunt <philh at vision25.demon.co.uk> wrote:
> Is there a function in the standard Python library to HTML-ize text,
> i.e. to replace 'a > b & c < d' with 'a > b & c < d'?

>>> import cgi
>>> cgi.escape('a > b & c < d')
'a > b & c < d'

> (I realize this can be done with regular expressions, but is there
> an easy way?)

hmm.  doing this with regular expressions seems a bit
backwards.  but I might be missing something...

(for info on how to go from escaped entities to plain
text, see the 'htmlentitydefs-example-2.py' script in
the eff-bot guide).

</F>

<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->





More information about the Python-list mailing list