#!/usr/bin/env python __author__ = ‘氨蛋三键‘ class Tracer: def __init__(self, fun): self.calls = 0 self.fun = fun def __call__(self, *args, **kwargs): self.calls += 1 print("Tracer 第 %s 次调用的函数是 %s " % (self.calls, self.fun.__name__)) self.fun(*args, **kwargs) class TestDemo: @Tracer def fun(*args, **kwargs): print(*args, **kwargs) if __name__ == "__main__": td = TestDemo() td.fun(1, 2, 3, 4, 5, 6, 7)
执行结果是:
Tracer 第 1 次调用的函数是 fun 1 2 3 4 5 6 7
时间: 2024-10-13 20:09:05