Discuss / Python / 请编写一个decorator,能在函数调用的前后打印出'begin call'和'end call'的日志。

请编写一个decorator,能在函数调用的前后打印出'begin call'和'end call'的日志。

Topic source

lldhsds

#1 Created at ... [Delete] [Delete and Lock User]
请编写一个decorator,能在函数调用的前后打印出'begin call'和'end call'的日志。
from functools import wrapsdef mydecorator(func):    @wraps(func)    def wrapper(*args, **kwargs):        print('Before call!')        result = func(*args, **kwargs)        print('After call!')        return result    return wrapper@mydecoratordef f():    print('Function called!')f()

  • 1

Reply