Skip to content

Instantly share code, notes, and snippets.

@mkolod
Last active September 5, 2018 20:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkolod/ee1e539ce8aaf2bc99383a73d6bb322f to your computer and use it in GitHub Desktop.
Save mkolod/ee1e539ce8aaf2bc99383a73d6bb322f to your computer and use it in GitHub Desktop.
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()
@mkolod
Copy link
Author

mkolod commented Sep 5, 2018

Output:

my_var is 0
my_other_var is HAL

my_var is 1
my_other_var is IBM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment