function decorator-like function

Patrick Maupin pmaupin at
Sat Mar 27 19:07:47 CET 2010

On Mar 27, 11:24 am, vsoler < at> wrote:
> I see what happened. The first line was somehow hidden.
> Thank you very much.

You're welcome.  Sorry about the formatting.  Also, note that if your
decorator is complicated, you might want to use a class instead of a
nested function.  Here's the same thing, using a class (and using the
actual decorator syntax):

class d(object):
    def __init__(self, func):
        self.func = func
    def __call__(self, *args):
        print 3
        return self.func(*args)

def f(a, b):
    print a + b

f(5, 7)


More information about the Python-list mailing list