fork download
  1. class SleepyIterator:
  2. def __init__(self):
  3. self.count = 0
  4. self.end = 5
  5.  
  6. def __iter__(self):
  7. return self
  8.  
  9. def __next__(self):
  10. if self.count >= self.end:
  11. raise StopIteration("Too exhausted")
  12. count = self.count
  13. self.count += 1
  14. return count
  15.  
  16. def TakeNap(self):
  17. print('Zzzzz')
  18. self.end += 5
  19.  
  20. it = SleepyIterator()
  21.  
  22. for i in it:
  23. print(i)
  24.  
  25. it.TakeNap()
  26.  
  27. for i in it:
  28. print(i)
  29.  
Success #stdin #stdout 0.02s 9064KB
stdin
Standard input is empty
stdout
0
1
2
3
4
Zzzzz
5
6
7
8
9