escaping % in a string???

Amy G amy-g-art at cox.net
Fri Feb 27 02:12:47 EST 2004


I am trying to execute the following MySQL query:

c.execute("""DELETE FROM pending WHERE userid=%s AND subject LIKE '%%s%'"""
%(userid, phrase))

This returns an error saying:
ValueError: unsupported format character ''' (0x27) at index 63

I can fix this by setting
phrase = "%" + phrase + "%"

and then
c.execute("""DELETE FROM pending WHERE userid=%s AND subject LIKE '%s'"""
%(userid, phrase))

But is there a way to escape the % signs in the first execute statement?

Thanks in advance for any help.
Sorry about the easy question.






More information about the Python-list mailing list