escaping % in a string???

Amy G amy-g-art at cox.net
Fri Feb 27 08:59:19 CET 2004


Thanks for the quick response... exactly what I was looking for.


"Wolfram Kraus" <kraus at hagen-partner.de> wrote in message
news:c1ms95$mm3$1 at ork.noris.net...
> 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