Created
August 30, 2012 17:41
-
-
Save stober/3534845 to your computer and use it in GitHub Desktop.
A workaround for "static" variables in Python functions.
This file contains hidden or 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
#!/usr/bin/env python | |
''' | |
@author jstober | |
''' | |
def test_static(static=[0]): | |
static[0] += 1 | |
return static[0] | |
print test_static() # 1 | |
print test_static() # 2 | |
print test_static() # 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment