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'],
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, r.CosCAno,
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 row in
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 -
Hi all,
How to append a path (/var/myprog/src) to sys.path, but not in the dynamic
way like sys.path.apend(packpath), please?
I use debian os. and I'd tried to set the classpath in /etc/profile (export
CLASSPATH=...), and the pythonpath too (export PYTHONPATH=...). I found
it didn't work.
Best
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 solution