[Python-es] Convertir utf8 a html entities

Raimon Esteve raimonesteve en gmail.com
Mie Jun 6 20:02:26 CEST 2012


Bueno ¿y el ganador es ......?

>>> from htmlentitydefs import codepoint2name
>>> str = u'Això és un cançò'
>>> ''.join([ord(c) in codepoint2name and "&%s;" % codepoint2name[ord(c)] or c for c in str])
u'Això és un cançò'

Lo dejamos así, Almenos ha quedado compacto ;)

Saludos.

-- 
Si us plau, NO adjunti arxius a les seves respostes. Li preguem que
integri el text al cos del missatge. Pot respondre usant NetEtiquete
que li ajudarà a seguir la conversa.
http://es.wikipedia.org/wiki/Netiquette

Por favor, NO adjunte archivos a sus respuestas. Le rogamos que
integre el texto en el cuerpo del mensaje. Puede responder usando
NetEtiquete que le ayudará a seguir la
conversación.http://es.wikipedia.org/wiki/Netiquette

Please, DO NOT send attachment files with your answers, just copy and
paste only the text you need to send into the body of your mails.
Repply using NetEtiquete. http://en.wikipedia.org/wiki/Netiquette


Más información sobre la lista de distribución Python-es