import functools def log(*argu): def decorator(func): @functools.wraps(func) def wrapper(*args, **kw): print 'begin call' print '%s:' % func.__name__, for i in argu: print i, print '\nend call' return wrapper return decorator #@log('Rachel', 'Monica', 'Phoebe') @log() def friends(): pass friends()
结果:
begin call friends: Rachel Monica Phoebe end call
是不是被装饰函数都带参数,只是参数为不为空
Sign in to make a reply
瀛匀