escaping % in a string???

Wolfram Kraus kraus at hagen-partner.de
Fri Feb 27 08:40:24 CET 2004


Heyho!

Amy G wrote:
> I am trying to execute the following MySQL query:
> 
> c.execute("""DELETE FROM pending WHERE userid=%s AND subject LIKE
> '%%s%'""" %(userid, phrase))

Use %%
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.
> 

Stay Rude!
Wolfram




More information about the Python-list mailing list