TypeError: iter() returned non-iterator of type

来源:互联网 发布:界面汉化软件 编辑:程序博客网 时间:2024/06/08 06:20

</pre><strong>TypeError: iter() returned non-iterator of type</strong><p></p><pre name="code" class="python">class Fibs:    def __init__(self):        self.a = 0        self.b = 1    def next(self): #python3.0以后用__next__方法代替next方法        self.a, self.b = self.b, self.a + self.b        return self.a    def __iter__(self):        return self
</pre><pre name="code" class="python">

>>> fibs = Fibs()>>> for f in fibs:if f > 1000:print(f)breakTraceback (most recent call last):  File "<pyshell#41>", line 1, in <module>    for f in fibs:TypeError: iter() returned non-iterator of type 'Fibs'

在Python3.0版本及以后版本中用__next__魔法方法代替以前的next方法

0 0