A force d'embeter du monde avec ça, j'ai eu une solution sur irc. Donc merci à tamere sur #python-fr pour la solution, la voici :
import htmlentitydefs
dico = {}
for (k, v) in htmlentitydefs.entitydefs.items() :
dico[v] = k
machaine = "lé aquesant cé bô"
for c in machaine :
try :
print "&%s;" % dico[c]
except KeyError :
print c
# Solution (à moi même)
Posté par huats . En réponse au message Transformation de chaîne en chaîne "à la html". Évalué à 2.
import htmlentitydefs
dico = {}
for (k, v) in htmlentitydefs.entitydefs.items() :
dico[v] = k
machaine = "lé aquesant cé bô"
for c in machaine :
try :
print "&%s;" % dico[c]
except KeyError :
print c