Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import types
- from functools import wraps
- def recurse(fn):
- @wraps(fn)
- def wrapper(self):
- v = fn(self)
- @recurse
- @wraps(fn)
- def replacement(self):
- return v + 1
- setattr(self, fn.__name__, types.MethodType(replacement, self))
- return v
- return wrapper
- class Wtf(object):
- @recurse
- def value(self):
- return 4
- x = Wtf()
- print x.value()
- print x.value()
- print x.value()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement