Clodoaldo <[EMAIL PROTECTED]> wrote: > On May 29, 12:57 pm, "Richard Brodie" <[EMAIL PROTECTED]> wrote: >> "Clodoaldo" <[EMAIL PROTECTED]> wrote in message >> >> news:[EMAIL PROTECTED] >> >> >I was looking for a function to transform a unicode string into >> >htmlentities. >> >>> u'São Paulo'.encode('ascii', 'xmlcharrefreplace') >> >> 'São Paulo' > > That was a fast answer. I would never find that myself. > You might actually want:
>>> cgi.escape(u'São Paulo & Espírito Santo').encode('ascii', >>> 'xmlcharrefreplace') 'São Paulo & Espírito Santo' as you have to be sure to escape any ampersands in your unicode string before doing the encode. -- http://mail.python.org/mailman/listinfo/python-list