Skip to content

Instantly share code, notes, and snippets.

@dmohs
Last active July 27, 2017 16:14
Show Gist options
  • Save dmohs/cfb445b50a2c20e20fab78139a7807e4 to your computer and use it in GitHub Desktop.
Save dmohs/cfb445b50a2c20e20fab78139a7807e4 to your computer and use it in GitHub Desktop.
Python does not always scope variables correctly.
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