How to escape HTML with characters like –
in Python?
views:
305answers:
1
+2
A:
If you have a unicode string as input, you can use the xmlcharrefreplace error handler:
py> u"<p>\N{EN DASH}</p>".encode("ascii", "xmlcharrefreplace")
'<p>–</p>'
Martin v. Löwis
2009-08-08 16:52:23