Guest User

Untitled

a guest
May 23rd, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. from collections import Iterator
  2.  
  3. class Foo(Iterator):
  4. def __init__(self, stop):
  5. self.x = 0
  6. self.stop = stop
  7.  
  8. def __iter__(self):
  9. return self
  10.  
  11. def next(self):
  12. if self.x < self.stop:
  13. i = self.x
  14. self.x += 1
  15. return i
  16. else:
  17. raise StopIteration
  18.  
  19. __next__ = next # Python 3 compatibility
  20.  
  21.  
  22. foo = Foo(10)
  23. for n in foo:
  24. print(n),
Advertisement
Add Comment
Please, Sign In to add comment