def log(text): def decorator(func): def wrraper(*args,**kwargs): if(isinstance(text,str)): print('%s: call %s()' % (text, func.__name__)) else: print('call %s()'%text.__name__) return func(*args,*kwargs) return wrraper return decorator if(isinstance(text,str)) else decorator(text)
要点:
(isinstance(text,str)) 若是加字符串的话返回函数名称: 调用执行为:log(text)(func)=>decorator(func)=>wrraper备用 若不是字符串的话直接执行decorator(text)其中text即func 调用执行为:log(func)(func)=>decorator(func)=>wrraper用,实只有log的时候就直接执行的decorator(func)
(isinstance(text,str))
Sign in to make a reply
阿花的阿发
要点:
(isinstance(text,str))
若是加字符串的话返回函数名称: 调用执行为:log(text)(func)=>decorator(func)=>wrraper备用 若不是字符串的话直接执行decorator(text)其中text即func 调用执行为:log(func)(func)=>decorator(func)=>wrraper用,实只有log的时候就直接执行的decorator(func)