Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import Iterator
- class Foo(Iterator):
- def __init__(self, stop):
- self.x = 0
- self.stop = stop
- def __iter__(self):
- return self
- def next(self):
- if self.x < self.stop:
- i = self.x
- self.x += 1
- return i
- else:
- raise StopIteration
- __next__ = next # Python 3 compatibility
- foo = Foo(10)
- for n in foo:
- print(n),
Advertisement
Add Comment
Please, Sign In to add comment