[newbie] Right way to access item in array?
steve at holdenweb.com
Tue Oct 28 14:56:11 CET 2008
Gilles Ganault wrote:
> I'd like to know what the right way is to access an item in a row as
> returned by a database:
> import apsw
> rows=cursor.execute("SELECT isbn,price FROM books WHERE price IS
If you are dealing with a DB API-compliant module then the return value
from the cursor's execute method is undefined, and you need to call one
of the "fetch" methods to extract the retrieved data.
So you would want something like
cursor.execute("SELECT isbn,price FROM books WHERE price IS NULL")
rows = cursor.fetchall()
for isbn, price in rows:
print isbn, ":", price
Once you get that working you can do your own computations with isbn and
price. Note, however, that the specific query you use guarantees that
the value of "proce" will be None, since you only retrieve the rows
where price is NULL!
> for row in rows:
> #Is this right?
> for isbn in row:
> if isbn:
> print "Found price = " + price
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
More information about the Python-list