I have a string where special characters like ' or " or & (…) can appear. In the string:
string = """ Hello "XYZ" this 'is' a test & so on """
how can I automatically escape every special character, so that I get this:
string = " Hello "XYZ" this 'is' a test & so on "
In Python 3.2, you could use the
html.escapefunction, e.g.For earlier versions of Python, check http://wiki.python.org/moin/EscapingHtml: