Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
90
rated 0 times [  92] [ 2]  / answers: 1 / hits: 111256  / 14 Years ago, tue, september 14, 2010, 12:00:00

Consider:



>>> sample = hello'world
>>> print sample
hello'world
>>> print sample.replace(',')
hello'world


In my web application I need to store my Python string with all single quotes escaped for manipulation later in the client browsers JavaScript. The trouble is Python uses the same backslash escape notation, so the replace operation as detailed above has no effect.



Is there a simple workaround?


More From » python

 Answers
45

Use:



sample.replace(', r')


or



sample.replace(', \')

[#95630] Saturday, September 11, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
randall

Total Points: 492
Total Questions: 99
Total Answers: 103

Location: Solomon Islands
Member since Fri, Oct 8, 2021
3 Years ago
;