> 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.
>
I should add the disclaimer that namedtuple is only available in Python 2.6+
_
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 "c
> I really like Ricardo's solution ... attribute access is a nice touch,
> bookmarking it now.
>
> FWIW, it would seem that psycopg2 also has a DictCursor (and
> DictConnection).
>
> http://initd.org/psycopg/docs/extras.html
>
>
> Ah, yes, there it is. Thank you. This list rocks!
__
Serdar Tumgoren wrote:
> Hey everyone,
>
> Ricardo was nice enough to post his solution as a recipe on ActiveState.
> For anyone interested in bookmarking it, here's the link:
>
> http://code.activestate.com/recipes/577186-accessing-cursors-by-field-name/
>
> Serdar
>
I really like Ricardo's s
Hey everyone,
Ricardo was nice enough to post his solution as a recipe on ActiveState. For
anyone interested in bookmarking it, here's the link:
http://code.activestate.com/recipes/577186-accessing-cursors-by-field-name/
Serdar
___
Tutor maillist - T
Serdar Tumgoren wrote:
> Hi folks,
>
> Does anyone know if there's native support in psycopg2 for accessing
> rows in a result-set by column name (rather than by index)?
>
> I'd like to be able to do something like below:
>
> cur.execute('select id, name from mytable')
> data = cur.fetchall()
> for
> >>> class reg(object):
> ... def __init__(self, cursor, registro):
> ... for (attr, val) in zip((d[0] for d in cursor.description),
> registro) :
> ... setattr(self, attr, val)
>
> >>> for row in cursor.fetchall() :
> ... r = reg(cursor, row)
> ... print r.CosCPrd,
Hi folks,
Does anyone know if there's native support in psycopg2 for accessing rows in
a result-set by column name (rather than by index)?
I'd like to be able to do something like below:
cur.execute('select id, name from mytable')
data = cur.fetchall()
for row in data:
print row['id'], row['