making a variable available in a function from decorator
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Mon Jul 30 02:17:25 EDT 2007
On Sun, 29 Jul 2007 15:22:47 -0700, rkmr.em at gmail.com wrote:
> I create a variable in a decorator. i want to be able to access that
> variable in the function to be decorated. How to do this?
Pass it as argument to the function:
def deco(func):
eggs = 42
def decorated(*args, **kwargs):
kwargs['spam'] = eggs
func(*args, **kwargs)
return decorated
@deco
def test(parrot, spam):
print parrot, spam
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list