t553.py 590 B

1234567891011121314151617181920212223242526272829303132
  1. from time import sleep
  2. class GeneratorClass:
  3. test = "hi"
  4. def __init__(self):
  5. pass
  6. def generator(self):
  7. print self.test
  8. for i in range(10):
  9. yield i
  10. def sleeping_generator(self):
  11. print self.test
  12. for i in range(10):
  13. sleep(0.01)
  14. yield i
  15. gen = GeneratorClass()
  16. for g in gen.generator():
  17. print g
  18. for g in gen.sleeping_generator():
  19. print g
  20. print list(gen.generator())
  21. print list(gen.sleeping_generator())
  22. print [x*2 for x in gen.generator()]
  23. print [x*2 for x in gen.sleeping_generator()]