title: How do I do string substitution in a query?
body: <p>I am trying to dynamically generate some sqlalchemy queries in Pyramid.</p>
  
  <pre><code>queries=[]
  if var1=='1':
    queries.append("Table.name.in_(['Dave'])")
  if var2=='2':
    queries.append("Table.last_name.in_(['Thomas'])") 
  
  qq = (','.join(queries))
  
  if len(queries) &gt; 1:
    query = DBSession.query(Table).filter(and_('%s')) % qq
  else:
    query = DBSession.query(Table).filter('%s') % qq
  </code></pre>
  
  <p>I get an error: <code>"TypeError: unsupported operand type(s) for %: 'Query' and 'str'"</code>
  How can I do that?</p>