fork download
  1. #!/usr/bin/env python3
  2.  
  3. class Obj():
  4. def __init__(self, word):
  5. self.word = word
  6.  
  7. def __iter__(self):
  8. for l in self.word:
  9. yield l
  10.  
  11. obj = Obj('sergey')
  12. it = iter(obj)
  13.  
  14. print(type(it))
  15.  
  16. n = next(it)
  17. print(type(n))
  18. print(n, len(n))
  19.  
  20. n = next(it)
  21. print(type(n))
  22. print(n, len(n))
  23.  
  24. n = next(it)
  25. print(type(n))
  26. print(n, len(n))
  27.  
  28. n = next(it)
  29. print(type(n))
  30. print(n, len(n))
  31.  
  32. n = next(it)
  33. print(type(n))
  34. print(n, len(n))
  35.  
  36. n = next(it)
  37. print(type(n))
  38. print(n, len(n))
  39.  
  40.  
  41.  
Success #stdin #stdout 0.04s 63648KB
stdin
Standard input is empty
stdout
<type 'generator'>
<type 'str'>
('s', 1)
<type 'str'>
('e', 1)
<type 'str'>
('r', 1)
<type 'str'>
('g', 1)
<type 'str'>
('e', 1)
<type 'str'>
('y', 1)