Skip to content

Instantly share code, notes, and snippets.

@jvanasco
Created July 3, 2018 23:24
Embed
What would you like to do?
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