Skip to content

Instantly share code, notes, and snippets.

@nooperpudd
Last active May 20, 2018 01:47
Show Gist options
  • Save nooperpudd/07509ceff30089ee1aefc68b23a9e996 to your computer and use it in GitHub Desktop.
Save nooperpudd/07509ceff30089ee1aefc68b23a9e996 to your computer and use it in GitHub Desktop.
change stats
#https://coderwall.com/p/jo39na/python-decorators-using-self
# todo it inlater
states = {"a":"b", "b":"c", "c":"d", "d","end"}
class Foo:
#skip some staff
def will_change_state(f):
def wrapper(*args):
ret = f(*args)
args[0].change_state()
return ret
return wrapper
def change_state(self):
self.state = states[self.state]
@will_change_state
def func1(self):
pass
@will_change_state
def func2(self):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment