escaping % in a string???

From: Amy G (amy-g-art_at_cox.net)
Date: 02/27/04


Date: Thu, 26 Feb 2004 23:12:47 -0800

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.



Relevant Pages

  • Re: escaping % in a string???
    ... 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 ...
    (comp.lang.python)
  • Re: OT: Phrases I Hate
    ... blank stare from the younger set. ... What good is being an executive if you never get to execute anyone? ... saw my clipboard on the counter behind him. ... heard the phrase in 25 years, the words that came out of my mouth were ...
    (alt.fan.letterman)
  • Re: OT: Phrases I Hate
    ... blank stare from the younger set. ... What good is being an executive if you never get to execute anyone? ... saw my clipboard on the counter behind him. ... heard the phrase in 25 years, the words that came out of my mouth were ...
    (alt.fan.letterman)
  • Re: How is "mista" used?
    ... From a male using this phrase ... Does this more commonly mean a buddy, of a hot female companion? ... What good is being an executive if you never get to execute anyone? ...
    (alt.usage.english)
  • Re: Whats that all about?
    ... A search confirms that Jerry Seinfeld used it routinely. ... Life is a mystery and it's an unsolvable one. ... A similar phrase even more associated with Jerry Seinfeld is "what is the deal ... What good is being an executive if you never get to execute anyone? ...
    (alt.usage.english)