function decorator-like function

Patrick Maupin pmaupin at gmail.com
Sat Mar 27 14:07:47 EDT 2010


On Mar 27, 11:24 am, vsoler <vicente.so... at gmail.com> 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)
@d
def f(a, b):
 print a + b
f(5, 7)
Pat


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /