Htmlizing text

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

Phil Hunt <philh at> 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 '' script in
the eff-bot guide).


<!-- (the eff-bot guide to) the standard python library:

More information about the Python-list mailing list