import timedef wrapper(func): def inner(*args,**kwargs): """函数执行之前的操作""" start_time=time.time() time.sleep(4) res=func(*args,**kwargs) dur=time.time()-start_time print("该函数的执行时间:%s" %dur) """函数执行后执行的操作""" return res return inner@wrapperdef lin(str): len = 0 for i in str: len+=1 print(‘该字符串长度为;%s‘ %len) return "装饰器函数"link=lin(‘123134‘)print(link)
原文地址:https://www.cnblogs.com/sihong/p/11049568.html
时间: 2024-10-05 00:08:00