Created
November 18, 2014 21:46
-
-
Save akesterson/e4cc27127c1374850f83 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 wat(): | |
... raise Exception("ARGH") | |
... yield 0 | |
... yield 1 | |
... yield 2 | |
... | |
>>> wat() | |
<generator object wat at 0x2e62500> | |
>>> for item in wat(): | |
... print item | |
... | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "<stdin>", line 2, in wat | |
Exception: ARGH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
freenode #python set me straight on this one
[13:50] dash: akesterson: mmm, nope, exceptions work like normal
[13:50] akesterson: see the gist, no they don't. Not in 2.6 and 2.76
[13:50] akesterson: s/2.76/2.7/
[13:50] dash: akesterson: yes, that's exceptions working like normal
[13:50] dash: akesterson: as soon as the raise statement is run, the exception is raised
[13:51] dash: akesterson: calling a generator function creates a generator object but doesn't run anything in the function body
[13:51] dash: akesterson: that happens when the generator is iterated over
[13:51] akesterson: dash: I see
[13:51] akesterson: that makes more sense and enrages me less
[13:51] dash: akesterson: so, 'wat()' does not raise an exception because the raise statement hasn't been run yet