[Tutor] accessing Postgres db results by column name

Serdar Tumgoren zstumgoren at gmail.com
Mon Apr 12 22:01:04 CEST 2010


Hey folks,

Wanted to send along one more update about this topic. Steve Orr pointed out
in a comment on Ricardo's new recipe that there's yet another way to get
named attribute access to cursor results.

The secret sauce is namedtuple, "high performance" collection type.  This
appears to be the "canonical" approach these days:

http://code.activestate.com/recipes/500261/

The Python Docs have a nice little example of this approach, using both the
csv and sqlite3 modules:

http://docs.python.org/library/collections.html#namedtuple-factory-function-for-tuples-with-named-fields

And you can check out Steve's comment at the bottom of Ricardo's recipe:

http://code.activestate.com/recipes/577186-accessing-cursors-by-field-name/

Regards,

Serdar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100412/0132fc3d/attachment.html>


More information about the Tutor mailing list