using "private" parameters as static storage?
Aaron Brady
castironpi at gmail.com
Fri Nov 14 18:37:12 EST 2008
On Nov 13, 4:23 pm, Arnaud Delobelle <arno... at googlemail.com> wrote:
> def static(**vars):
> ns = NS(vars)
> def deco(f):
> return lambda *args, **kwargs: f(ns, *args, **kwargs)
> return deco
>
> @static(ncalls=0, history=[])
> def foo(ns, x):
> ns.ncalls += 1
> ns.history.append(x)
> print "Number of calls: %s\nHistory:%s" % (ns.ncalls, ns.history)
One could even add 'ns' as an attribute of 'f', so that the statics
were visible from the outside: 'foo.ns.ncalls'.
More information about the Python-list
mailing list