普通装饰器
from functools import wraps def cover(func): @wraps(func) def wrapper(*args, **kwargs): result = func(*args, **kwargs) return result return wrapper
类内部装饰器,可调用类内部函数
from functools import wraps class T(object): def __init__(self): pass def cover(func): """读取最新的数据到内存,写数据到硬盘""" @wraps(func) def wrapper(self, *args, **kwargs): do_something() result = func(self, *args, **kwargs) do_else() return result return wrapper @cover def get_schema(self, arg1, arg2): work...