関数デコレータ
.NETのCustomAttributeに近い印象。
>>> class Tracer: ... def __init__(self, func): ... self.cnt = 0 ... self.func = func ... def __call__(self, *args): ... self.cnt += 1 ... print(self.cnt) ... self.func(*args) ... >>> @Tracer ... def spam(a, b, c): ... print(a, b, c) ... >>> spam(1, 2, 3) 1 1 2 3