making a variable available in a function from decorator

Evan Klitzke evan at
Mon Jul 30 18:59:21 CEST 2007

On 7/30/07, rkmr.em at <rkmr.em at> wrote:
> is it possible to do this without passing it as a function argument?

Sort of. Functions are objects in python, so you can set attribute on them. E.g.

def foo():
    return foo.c

foo.c = 1
print foo()

Which will print 1. Of course, it would generally be better to write
your own class for this sort of thing, so that you can set the
variable in the instance scope.

Evan Klitzke <evan at>

More information about the Python-list mailing list