recursive decorator

Michele Simionato michele.simionato at
Sat Sep 5 06:25:07 CEST 2009

On Sep 4, 7:03 pm, Ethan Furman <et... at> wrote:

> Just to verify, using the decorator module is portable, yes?

Yes, it is portable. BTW, here is what you want to do (requires

from decorator import FunctionMaker

def bindfunc(f):
    name = f.__name__
    signature = ', '.join(FunctionMaker(f).args[1:]) # skip first arg
    return FunctionMaker.create(
        '%s(%s)' % (name,  signature),
        'return _func_(%s, %s)' % (name, signature),
        dict(_func_=f), defaults=f.func_defaults,
               doc=f.__doc__, module=f.__module__)

def fac(self, n):
    return 1 if n <= 1 else n * self(n - 1)

print fac(5)

More information about the Python-list mailing list