string - Escape double quotes for JSON in Python -
how can replace double quotes backslash , double quotes in python?
>>> s = 'my string "double quotes" blablabla' >>> s.replace('"', '\\"') 'my string \\"double quotes\\" blablabla' >>> s.replace('"', '\\\"') 'my string \\"double quotes\\" blablabla'
i following:
'my string \"double quotes\" blablabla'
>>> s = 'my string \\"double quotes\\" blablabla' >>> s 'my string \\"double quotes\\" blablabla' >>> print s string \"double quotes\" blablabla >>>
when ask 's' escapes \ you, when print it, see string more 'raw' state. now...
>>> s = """my string "double quotes" blablabla""" 'my string "double quotes" blablabla' >>> print s.replace('"', '\\"') string \"double quotes\" blablabla >>>
Comments
Post a Comment