import functools def log(text = None): def decorator(func): @functools.wraps(func) def wrapper(*args, **kw): if text is None: print('before call %s()' % func.__name__) else: print('before %s %s()' %(text, func.__name__)) result = func(*args,**kw) if text is None: print('after call %s()' % func.__name__) else: print('after %s %s()' %(text, func.__name__)) return wrapper return decorator @log('execute') def now(): print('2017-06-20') now()
Sign in to make a reply
lubang03