python类装饰器
# 例如
class A:
def __init__(self, func):
self.func = func
print(self.func)
def __call__(self, *args, **kwargs):
print("正在添加新功能...")
self.func(*args, **kwargs)
print("添加完毕")
return "ok"
# @A
def b(*args, **kwargs):
print("正在运行程序...")
print(args, kwargs)
b = A(b)
a = b(1, 3, 5, 7, dd="addr", bb="back")
print(a)
运行结果