Created
November 11, 2014 21:44
-
-
Save superbobry/44276d49244c381be649 to your computer and use it in GitHub Desktop.
Python generators and 'throw'
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 g(): | |
... yield 42 | |
... | |
>>> gen = g() | |
>>> next(gen) | |
42 | |
>>> gen.throw(RuntimeError) | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "<stdin>", line 2, in g | |
RuntimeError |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment