defargs_decorator(func): definner(*args, **kwargs): """ Closure Code :param *args: This allows the function to receive any number of positional arguments. It collects them into a tuple. :param **kwargs: This allows the function to receive any number of keyword arguments. It collects them into a dictionary. :return: result """ print("decorator---begin") result = func(*args, **kwargs) # 传递所有参数到原函数 print("decorator---end") return result
from functools import wraps deflx_decorator(func): @wraps(func) # 保留原函数元信息 This is important for debugging and introspection purposes, as it ensures that the decorated function retains the same identity as the original function. defwrapper(*args, **kwargs): print("decorator logic") return func(*args, **kwargs) return wrapper
@lx_decorator defexample_func(): """This is an example function.""" pass