And you should use cursor.fetchall() instead of cursor in list comprehension:<div><br></div><div>packageIDs = [itm[0] for itm in cursor.fetchall()]<br><br><div class="gmail_quote">On Sat, Jan 9, 2010 at 1:01 PM, Gabriel Genellina <span dir="ltr"><<a href="mailto:gagsl-py2@yahoo.com.ar">gagsl-py2@yahoo.com.ar</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">En Sat, 09 Jan 2010 11:01:25 -0300, Victor Subervi <<a href="mailto:victorsubervi@gmail.com" target="_blank">victorsubervi@gmail.com</a>> escribió:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
On Sat, Jan 9, 2010 at 8:39 AM, Tim Chase <<a href="mailto:python.list@tim.thechases.com" target="_blank">python.list@tim.thechases.com</a>>wrote:<br>
<br>
</div><div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
It would also help if you didn't pass the categoryID as a string-formatted<br>
value, but as a proper parameter, something like<br>
<br>
 sql = "... where c.categoryid=?" % (store, store)<br>
 cursor.execute(sql, (category_id,))<br>
<br>
</blockquote>
<br>
I now have the following:<br>
<br>
      sql = 'select distinct p.ID from %sPackages p join<br>
%sCategoriesPackages c where c.CategoryID=?;' % (store, store)<br>
      cursor.execute(sql, (categoryID,))<br>
      packageIDs = [itm[0] for itm in cursor]<br>
<br>
It threw this error:<br>
<br></div><div class="im">
TypeError: not all arguments converted during string formatting<br>
      args = ('not all arguments converted during string formatting',)<br>
<br>
</div><div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
You'd have to check the place-holder character for your particular<br>
back-end:<br>
<br>
 >>> import <your database engine> as db<br>
 >>> print db.paramstyle<br>
<br>
Printed "format". What's that mean? I use MySQLdb<br>
</blockquote></div></blockquote>
<br>
That means, MySQLdb uses %s as a placeholder for parameter substitution -- same as Python when doing string interpolation. Unfortunately this will confuse things. In your code above, the ? near the end should become %s -- but you don't want THAT %s to be interpreted by Python at that time, instead it must remain as a literal %s until the cursor.execute line. You have to escape the % by doubling it: %%s<br>


<br>
       sql = 'select distinct p.ID from %sPackages p join %sCategoriesPackages c where c.CategoryID=%%s;' % (store, store)<div class="im"><br>
       cursor.execute(sql, (categoryID,))<br>
       packageIDs = [itm[0] for itm in cursor]<br>
<br></div>
-- <br><font color="#888888">
Gabriel Genellina</font><div><div></div><div class="h5"><br>
<br>
-- <br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</div></div></blockquote></div><br></div>