[Tutor] escape-quoting strings

Marilyn Davis marilyn at deliberate.com
Mon Nov 1 00:06:56 CET 2004


I got it!!

This works:

ad0 = address.replace('\\', '\\\\')
ad0 = ad0.replace('\"','\\"')
db_style0 = '''%%%s%%''' % ad0
print "0:", db_style0

On Sun, 31 Oct 2004, Rick Pasotto wrote:

> On Sun, Oct 31, 2004 at 01:53:42PM -0800, Marilyn Davis wrote:
> > Hi Python Tutors,
> > 
> > I'm having a devil of a time quoting strings properly for MySql.
> 
> You example did not include any MySql statements. How are you sending
> the string to MySql?

I didn't want to complicate my question with MySql stuff.

Here is a successful call that depended on the quoting scheme above:

insert ignore into doorman (in_id,  msg_id, out_address, status, start) values         (60, "1COOZD-0003KN-2z", "\"Toys \\\"R\\\" Us Gift Card Giveaway\" <fqgdmvfjfyvjd at dlawczhyh.montebic.com>", "NO_MESSAGE", "0")

Thank you.

Marilyn




More information about the Tutor mailing list