[Tutor] accessing Postgres db results by column name
Serdar Tumgoren
zstumgoren at gmail.com
Fri Apr 9 23:08:08 CEST 2010
> >>> 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, r.CosCMes, r.CosCImpSis, r.CosCUsr
>
WOW!!! That works beautifully! Many many thanks!
Regards,
Serdar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100409/58242b96/attachment.html>
More information about the Tutor
mailing list