Last active
September 5, 2018 20:35
-
-
Save mkolod/ee1e539ce8aaf2bc99383a73d6bb322f to your computer and use it in GitHub Desktop.
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_var(name, value): | |
def helper(fun): | |
setattr(fun, name, value) | |
return fun | |
return helper | |
@static_var("my_var", 0) | |
@static_var("my_other_var", "HAL") | |
def foo(): | |
print("my_var is {}".format(foo.my_var)) | |
print("my_other_var is {}\n".format(foo.my_other_var)) | |
foo.my_var += 1 | |
foo.my_other_var = "".join(map(lambda x: chr(ord(x) + foo.my_var), foo.my_other_var)) | |
for i in range(2): | |
foo() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
my_var is 0
my_other_var is HAL
my_var is 1
my_other_var is IBM