making a variable available in a function from decorator

rkmr.em at gmail.com rkmr.em at gmail.com
Mon Jul 30 10:43:23 EDT 2007


is it possible to do this without passing it as a function argument?

On 30 Jul 2007 06:17:25 GMT, Marc 'BlackJack' Rintsch <bj_666 at gmx.net> wrote:
> 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
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list