Discuss / Python / 在函数调用的前后打印出'begin call'和'end call'的日志。

在函数调用的前后打印出'begin call'和'end call'的日志。

Topic source

林林1292

#1 Created at ... [Delete] [Delete and Lock User]

print('-------------') def log(perfix): def log_decorator(f): def wrapper(args,**kw): print('begin call %s()... ' % f.name) r = f(args,**kw) print('end call %s()... ' % f.name) return r return wrapper return log_decorator @log('DEBUG') def test(): print('This is the content of the function') test() print('----------------')


  • 1

Reply