今天爱分享给大家带来写出带参数的装饰器?【面试题详解】,希望能够帮助到大家。
from functools import wraps def decorator(*dargs, **dkwargs): def params_wrapper(func): @wraps(func) def wrapper(*args, **kwargs): func(*args, **kwargs) return wrapper return params_wrapper
类装饰器
class decorator(object): def __init__(self, func): self.func = func def __call__(self, *args, **kwargs): print('before............') res = self.func(*args, **kwargs) print('after............') return res