Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. >>> def comunicate():
  2. ...     print("passo1")
  3. ...     i = 0
  4. ...     try:
  5. ...         while True:
  6. ...             yield i
  7. ...             i += 1
  8. ...     except StopIteration:
  9. ...         print "passo3"
  10. ...
  11. >>>
  12. >>> a = comunicate()
  13. >>> a.next()
  14. passo1
  15. 0
  16. >>> a.next()
  17. 1
  18. >>> a.next()
  19. 2
  20. >>> a.throw(StopIteration)
  21. passo3
  22. Traceback (most recent call last):
  23.   File "<console>", line 1, in <module>
  24. StopIteration
  25. >>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement