Created
December 17, 2012 22:32
-
-
Save sahib/4323010 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> def co(): | |
... try: | |
... while True: | |
... item = yield | |
... print('Received:', item) | |
... except GeneratorExit: | |
... print('Exit.') | |
... | |
... | |
... | |
>>> g = co() | |
>>> g | |
<generator object co at 0x7fd3ce6e7a00> | |
>>> g.send(None) # Starte Generator. | |
>>> g.send('Berta') | |
Received: Berta | |
>>> g.send('Klaus') | |
Received: Klaus | |
>>> g.send('Seb') | |
Received: Seb | |
>>> g.send('') | |
Received: | |
>>> g.close() # werfe GeneratorExit innerhalb von co | |
Exit. | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment