错误1
错误代码
import time
def timer(func):
def deco():
start_time=time.time()
func()
stop_time=time.time()
print("运行方法耗时%s"%(stop_time-start_time))
return deco #此行没有缩进导致错误
@timer
def test1():
time.sleep(2)
print("in the test1")
test1()
输出:
Traceback (most recent call last):
File "D:/workspace/Pycharm/study/day4/装饰器+高阶函数.py", line 18, in <module>
test1()
TypeError: 'NoneType' object is not callable
错误原因:
return 没有缩进