[Disclaimer: there may be more pythonic ways of doing what I want to do, but I want to know how python\'s scoping works here]
I\'m trying to find a way to make a dec
Python is lexically scoped, so I'm afraid there is no clean way to do what you want without some potentially nasty side effects. I recommend just passing var into the function via the decorator.
c = 'Message'
def decorator_factory(value):
def msg_decorator(f):
def inner_dec(*args, **kwargs):
res = f(value, *args, **kwargs)
return res
inner_dec.__name__ = f.__name__
inner_dec.__doc__ = f.__doc__
return inner_dec
return msg_decorator
@decorator_factory(c)
def msg_printer(var):
print var
msg_printer() # prints 'Message'