On Nov 13, 4:23 pm, Arnaud Delobelle <[EMAIL PROTECTED]> 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'.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to