[Tutor] problem with building dict w/ SQlite SELECTS in loop

Tim Golden mail at timgolden.me.uk
Tue Sep 16 10:00:57 CEST 2008


Che M wrote:
> (struggling to make an informative subject line)

[ struggling to understand exactly what the problem is... :) ]

I'm quite willing to help on this, but it's just not quite
clear enough what's happening. Can I suggest that you
post a *really small, self-contained* example which demonstrates
the problem you're having. You might actually realise what's
wrong as you do that, or if not someone like me can just run
the example and see what you mean and point things out.

Your code is missing just too many things for me
to work out which bit is doing what. (And it's a bit
awkward because of the long lines).

Try posting something like this:

<code>
import sqlite3

db = sqlite3.connect (":memory:")
db.execute ("CREATE TABLE codes (code)")
db.executemany ("INSERT INTO codes VALUES (?)", [(i,) for i in range (10)])

q = db.cursor ()
for n_try in range (3):
  q.execute ("SELECT * FROM codes WHERE code > ?", [n_try])
  q.fetchall ()

q.close ()

</code>


and say what you think should happen, and what does
happen. Note that the entire code I've posted there
can be dropped straight into an interpreter and run
which makes it much easier for people who are willing
to help to see what you're trying to do.

TJG


More information about the Tutor mailing list