Created
July 3, 2018 23:24
-
-
Save jvanasco/86bc172066a5c8a557f945107a82e784 to your computer and use it in GitHub Desktop.
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