def record(func): def wrapper(*args, **kwargs): print("Call function: {}".format(func.name)) return func(*args, **kwargs) return wrapper

@record def func1(): print("This is function 1")

@record def func2(): print("This is function 2")

func1() func2()

编写装饰器:为多个函数加上记录调用功能要求每次调用函数都将被调用函数的名称打印出来。提示:函数对象有个属性__name__可以得到一个函数的名称。要求用python实现

原文地址: http://www.cveoy.top/t/topic/cFcm 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录