Created
October 20, 2014 05:19
-
-
Save oxnz/1d524a1cf58e0a2b40ad to your computer and use it in GitHub Desktop.
python function static variable use decorator
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 static_variable(name, val): | |
def decorate(func): | |
setattr(func, name, val) | |
return func | |
return decorate | |
@static_variable('static_a', 10) | |
def test(): | |
print test.a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment