Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class GlobalCaller(object):
- def __init__(self, method, value):
- self.method = method
- self.value = value
- def __call__(self, *args, **kwargs):
- added = False
- curr_globals = self.method.func_globals
- if 'a' not in curr_globals:
- curr_globals['a'] = self.value
- added = True
- result = self.method(*args, **kwargs)
- if added:
- curr_globals.pop('a')
- return result
- def deco(value):
- def actual_deco(method):
- return GlobalCaller(method, value)
- return actual_deco
- @deco(99)
- def f():
- return a
- @deco(9)
- def g(b):
- return a + b
- print f()
- print g(1)
Advertisement
Add Comment
Please, Sign In to add comment