标签:src turn return span ide index rom func cdb
1.
import time
def index():
print(‘welcome‘)
time.sleep()
return 123
def outter(func):
#func=最原始的那个index的内存地址
def wrapper():
start=time.time()
res=func()#最原始那个index的内存地址()
stop=time.time()
print(‘time is %s‘%(stop-start))
return res
return wrapper
index=outter(index)#index=outter(最原始那个index的内存地址)
#index=wrapper函数的内存地址
res=index()
print(res)
2.
import time
def index():
print(‘welcome‘)
time.sleep(1)
return 125
def home(name):
print(‘welcome %s‘%name)
time.sleep(1)
def outter(func):
#func=最原始那个home的内存地址
def wrapper(*args,**kwargs):
start=time.time()
res=func(*args,**kwargs)
stop=time.time()
print(‘time is %s‘%(stop-start))
return res
return wrapper
index=outter(index)#index=outter(最原始那个index的内存地址)#index=wrapper函数的内存地址
home=outter(home) #index=outter(最原始那个home的内存地址)#home=wrapper函数的内存地址
home(‘han‘)#wrapper(‘han‘)
res=index()#wrapper
print(res)
# @装饰器的名字:要在被装饰对象正上方单独一行写上
import time def timmer(func): # func=最原始那个home的内地址 def wrapper(*args,**kwargs): start=time.time() res=func(*args,**kwargs) stop=time.time() print(‘run time is %s‘ %(stop-start)) return res wrapper.__doc__=func.__doc__ wrapper.__name__=func.__name__ return wrapper @timmer #index=timmer(index) ##index=timmer(最原始那个index的内地址) #index=wrapper函数的内地址 def index(): """这是index功能""" print(‘welcome to index page‘) time.sleep(3) return 123 @timmer #home=timmer(home) #index=timmer(最原始那个home的内地址) #home=wrapper函数的内地址 def home(name): """这是home功能""" print(‘welcome %s to home page‘ %name) time.sleep(1) # home(‘egon‘) #wrapper(‘egon‘) # index() #wrapper() # print(help(index)) # print(help(home)) # print(index.__doc__) print(index.__name__) ‘‘‘ from functools import wraps import time def timmer(func): # func=最原始那个home的内地址 @wraps(func) def wrapper(*args,**kwargs): start=time.time() res=func(*args,**kwargs) stop=time.time() print(‘run time is %s‘ %(stop-start)) return res return wrapper @timmer def index(): """这是index功能""" print(‘welcome to index page‘) time.sleep(3) return 123 @timmer def home(name): """这是home功能""" print(‘welcome %s to home page‘ %name) time.sleep(1) print(help(index)) print(index.__name__)
标签:src turn return span ide index rom func cdb
原文地址:https://www.cnblogs.com/xiamenghan/p/9715426.html