Qualcuno può spiegare perché il seguente codice sta dandoTipo errore Iter - python3
TypeError: iter() returned non-iterator of type 'counter' in python 3
Questo è il lavoro in Python 2.7.3 senza alcun errore.
#!/usr/bin/python3
class counter(object):
def __init__(self,size):
self.size=size
self.start=0
def __iter__(self):
print("called __iter__",self.size)
return self
def next(self):
if self.start < self.size:
self.start=self.start+1
return self.start
raise StopIteration
c=counter(10)
for x in c:
print(x)