Converting text to html

Robin Munn rmunn at
Sat Apr 5 01:49:03 CEST 2003

achrist at <achrist at> wrote:
> Is there any recommended code available to convert plain text into
> text that can go into an html document without breaking it?  I 
> think that I just have to do these three translations:
> 	< =>  <	> =>  >   & 	=>  &
> But I'm not sure if there are any others.  I've got to do this 
> quite a bit while the user is waiting, so it would be nice to
> have something that did it in a way that was not a lot slower
> than any of the alternatives.  
> Surely someone must have cracked this nut sys.maxint times by now.

You want the cgi module, and specifically the cgi.escape() function.

See and also the
bottom of for more.

Hope this helps.

Robin Munn <rmunn at>
PGP key ID: 0x6AFB6838    50FF 2478 CFFB 081A 8338  54F7 845D ACFD 6AFB 6838

More information about the Python-list mailing list