停止迭代错误和记录

时间:2017-03-20 13:56:47

标签: python python-3.x

我正在使用Kenneth ritz优秀的记录库来连接关系数据库

rec = db.query('select * from dept')
for r in rec:
    print(rec.next)

<bound method RecordCollection.next of <RecordCollection size=1 pending=True>>
<bound method RecordCollection.next of <RecordCollection size=2 pending=True>>
<bound method RecordCollection.next of <RecordCollection size=3 pending=True>>
<bound method RecordCollection.next of <RecordCollection size=4 pending=True>>
C:\Python36\Scripts\ipython3:1: DeprecationWarning: generator 'RecordCollection.__iter__' raised StopIteration

我正在尝试迭代数据库查询的结果但是在迭代之后我得到一个令人讨厌的异常任何想法

  • a)为什么我要点这个例外?
  • b)什么是正确的方法 迭代结果集?

我试过这个

In [63]: for r in rec:
    ...:     print(r)
    ...:
    ...:
    ...:
<Record {"deptno": 10, "dname": "ACCOUNTING", "loc": "NEW YORK"}>
<Record {"deptno": 20, "dname": "RESEARCH", "loc": "DALLAS"}>
<Record {"deptno": 30, "dname": "SALES", "loc": "CHICAGO"}>
<Record {"deptno": 40, "dname": "OPERATIONS", "loc": "BOSTON"}>
C:\Python36\Scripts\ipython3:1: DeprecationWarning: generator 'RecordCollection.__iter__' raised StopIteration

我仍然得到StopIteration警告

0 个答案:

没有答案