[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
Here is a simple demonstration of using a decorator to add a variable into the scope of a function.
>>> def add_name(name):
... def inner(func):
... # Same as defining name within wrapped
... # function.
... func.func_globals['name'] = name
...
... # Simply returns wrapped function reference.
... return func
...
... return inner
...
>>> @add_name("Bobby")
... def say_hello():
... print "Hello %s!" % name
...
>>> print say_hello()
Hello Bobby!
>>>