escaping only double quotes

C

cesco

Hi,

I have a string which is constructed like this:

string = "Butler's 15\" TV"
s = """my string goes here "%s" """ % string

the single string, unfortunately, gets escaped which is something I
want to avoid because I have to load the data into a database using
the json format and I get an "invalid escape error" if the single
quote is escaped.

Is there a way to accomplish this?

Thanks and regards
Francesco
 
I

iapain

string = "Butler's 15\" TV"
s = """my string goes here "%s" """ % string

Couldn't find anything wrong in

string = "Butler's 15\" TV"
s = "my string goes here %s" % string
 
I

iapain

You could write a simple escape function.

def escape(html):
"Return the given TEXT with ampersands, quotes and carets
encoded."
return html.replace('&', '&amp;').replace('<',
'&lt;').replace('>', '&gt;').replace('"', '&quot;').replace("'",
''')
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top