CR LF

Fredrik Lundh effbot at telia.com
Tue Sep 5 16:09:35 EDT 2000


jonadab wrote
> > You also need to change < to <, etc, etc (not sure if some standard
> > Python library module already has that functionality...?).
> 
> A series of regular-expression replaces seems to be in order.
> I don't (yet!) know Python, but in elisp or Perl this would be
> pretty trivial, so I expect Python should be able to do it also.
>
> Something like this elisp...
> 
> (replace-string "&" "&")
> (replace-string "<" "<")
> (replace-string ">" ">")
> (replace-string "\"" """)
> (replace-regexp "^" "<div>")
> (replace-regexp "$" "</div>")
> 
> Or, in Perl, ...
> 
> s/\&/&/;
> s/</</;
> s/>/>/;
> s/\"/"/;
> s/^/<div>/;
> s/$/<\/div>/;

or, in Python:

   string = cgi.escape(string)

(this is comp.lang.python, after all).

</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