shameful python
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 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