停止迭代错误和记录

2024-04-20 07:24:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用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

我还是收到了那个警告


Tags: ofintrueforsizerecordmethodloc