Possible Duplicate:
Build a Basic Python Iterator
What are the required methods for defining an iterator? For instance, on the following Infinity
iterator, are its methods sufficient? Are there other standard or de facto standard methods that define an iterator?
class Infinity(object):
def __init__(self):
self.current = 0
def __iter__(self):
return self
def next(self):
self.current += 1
return self.current