[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
There is a clean way to do what you want without using global variable. If you want to be stateless and threads safe, you don't really have the choice.
Use the "kwargs" variable:
c = 'Message'
def decorator_factory(value):
def msg_decorator(f):
def inner_dec(*args, **kwargs):
kwargs["var"] = value
res = f(*args, **kwargs)
return res
return inner_dec
return msg_decorator
@decorator_factory(c)
def msg_printer(*args, **kwargs):
print kwargs["var"]
msg_printer()