Skip to content

Instantly share code, notes, and snippets.

@jvanasco
Created July 3, 2018 23:24
Show Gist options
  • Save jvanasco/86bc172066a5c8a557f945107a82e784 to your computer and use it in GitHub Desktop.
Save jvanasco/86bc172066a5c8a557f945107a82e784 to your computer and use it in GitHub Desktop.
shameful python
def foo():
# i am awful for doing this.
# this function has a nested function, which can not accept arguments
# the inner function will be called twice by a 3rd party library
iteration = [0, ] # use a list as a shameful hack to get around scoping issues
def bar():
iteration[0] += 1 # increment the list index, use that for comparison
if iteration[0] > 1:
print "iteration[0] > 1"
else:
print "! first run"
bar()
bar()
bar()
bar()
foo()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment