装饰器修改实例参数
def my_decorator(func):
def wrapper(*args, **kwargs):
print(args)
if args[0].cache:
print("GET CACHE ====> ", args[0].cache)
args[0].cache = "cache"
return func(*args, **kwargs)
return wrapper
class MyClass:
def __init__(self):
self.cache = ""
@my_decorator
def my_run(self):
pass
if __name__ == '__main__':
demo = MyClass()
demo.my_run()
demo.my_run()