[DB-SIG] fetchone -> dictionary?

M.-A. Lemburg mal@lemburg.com
Wed, 20 Jan 1999 17:08:41 +0100


Stephen Ng wrote:
> 
> I'm just getting started with this stuff, so sorry if this is a newbie 
> question/suggestion.
> 
> Why not have a flavor of fetchone() which returns a dictionary instead a
> sequence?  Then we could write:
> 
> row = dfetchone()
> print row['FieldName']
> 
> instead of
> 
> print row[SomeConstantWhichMightChange]
> 
> Perhaps dfetchall could be implemented as an array of dictionaries?

You can easily achieve this using a Python function (or maybe
even a Python class wrapping the DB API cursor interface).
The needed position -> name mapping is available through
cursor.desription.

-- 
Marc-Andre Lemburg                               Y2000: 345 days left
---------------------------------------------------------------------
          : Python Pages >>> http://starship.skyport.net/~lemburg/  :
           ---------------------------------------------------------