Last active
July 27, 2017 16:14
-
-
Save dmohs/cfb445b50a2c20e20fab78139a7807e4 to your computer and use it in GitHub Desktop.
Python does not always scope variables correctly.
This file contains 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 do_i_suck_at_scoping(): | |
try: | |
import gc | |
y = [x for x in range(5)] | |
gc.collect() # Just to prove this isn't a garbage collection issue. | |
x # Should throw a NameError since it is undefined. | |
assert False, '''Sorry, I don't know how to properly scope variables.''' | |
except NameError: | |
pass | |
do_i_suck_at_scoping() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment