I am trying to execute a mysql query, which needs to contain % characters… While building the query, I run into a problem of python using % and trying to stick it as a variable:
statmt="select id from %s WHERE `email` LIKE %blah%" % (tbl)
self.cursor.execute(statmt)
This naturally barfs with:
statmt="select id from %s WHERE `email` LIKE %blah%" % (tbl)
TypeError: not enough arguments for format string
How should I fix this so Python stops reading this as a variable, and takes it in as part of the string?
Thanks!
When needing a literal
%inside a Python formatting expression, use%%:See the documentation section 5.6.2. String Formatting Operations for more information.