import functools def my_decorator(func): @functools.wraps(func) def wrapper(*args, **kwargs): print("Something is happening before the function is called.") result = func(*args, **kwargs) print("Something is happening after the function is called.") return result return wrapper @my_decorator def example(): """This is an example function.""" print("The function is called.") print(example.__name__) Output: example print(example.__doc__) Output: This is an example function.
点赞 评论

相关推荐

牛客网
牛客网在线编程
牛客网题解
牛客企业服务