迭代器功能:
不更改操作函数名的前提下,修改原函数功能!
例如:
import time
def show_time(func):
def wrapper():
start_time = time.time()
func()
end_time = time.time()
print('spend %s' % (end_time - start_time))
return wrapper
@show_time #作用相当于foo = show_time(foo)
def foo():
print('hello foo')
time.sleep(3)
#foo = show_time(foo) 由于前面存在@show_time 所以可省
foo()