Python psycopg2 error vars function

扶醉桌前 提交于 2019-12-07 08:21:27

You are using a psycopg2.extras.NamedTupleCursor, which produces instances of a class produced with the collections.namedtuple() class factory. These classes use __slots__ to limit their memory use.

Normally, classes with __slots__ don't have a __dict__ attribute. However, in Python 2.7.3 a __dict__ property was added (see revision 26d5f022eb1a), specifically to support vars() use. A later change removed the support again from Python 2.7.5, then it was readded for Python 2.7.6. The property acts as a proxy, calling namedtuple._asdict() to produce an OrderedDict object.

You have a Python 2.7.x release that doesn't have the property; e.g. one of 2.7, 2.7.1, 2.7.2 or 2.7.5. You can work around this by calling the namedtuple._asdict() method instead:

for row in dbCur:
    print type(row)
    print row._asdict()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!