가능한 중복 :
Build a Basic Python Iterator파이썬 이터레이터의 인터페이스는 무엇입니까?
반복자를 정의하기위한 필요한 방법은 무엇입니까? 예를 들어 다음 Infinity 반복기에서는 메서드가 충분합니까? 반복기를 정의하는 다른 표준 또는 de factor 표준 메소드가 있습니까?
class Infinity(object):
def __init__(self):
self.current = 0
def __iter__(self):
return self
def next(self):
self.current += 1
return self.current
@Arion : 그냥 문을'추가, 모두를 정의하려면 __next__ = next' 클래스의 끝에. – martineau