title: How can I format strings to query with mysqldb in Python?
body: <p>How do I do this correctly:</p>
  
  <p>I want to do a query like this:</p>
  
  <p><pre><code>query = """SELECT * FROM sometable 
                      order by %s %s 
                      limit %s, %s;"""
  conn = app_globals.pool.connection()
  cur = conn.cursor()
  cur.execute(query, (sortname, sortorder, limit1, limit2) ) 
  results = cur.fetchall()
  </pre></code></p>
  
  <p>All works fine but the order by %s %s is not putting the strings in correctly. It is putting the two substitutions in with quotes around them. </p>
  
  <p>So it ends up like:
  <pre><code>ORDER BY 'somecol' 'DESC'</pre></code></p>
  
  <p>Which is wrong should be:
  <pre><code>ORDER BY somecol DESC</pre></code></p>
  
  <p>Any help greatly appreciated! </p>