import functools def log(test=""): def decorator(func): @functools.wraps(func) def wrappers(*args,**kw): print("%s begin call : %s" % (test,func.__name__)) result = func(*args,**kw) print("%s end call : %s "% (test,func.__name__)) return result return wrappers return decorator @log('execute') def now(): print('2016-01-16') now() print("==============") @log() def now(): print('2016-01-16') now()
结果是:
execute begin call : now 2016-01-16 execute end call : now ============== begin call : now 2016-01-16 end call : now
Sign in to make a reply
TableFinisher
结果是: