在python3.8下运行如下代码
import time
a = []
t0 = time.clock()
for i in range(1,1000):
a.append(i)
print(time.clock() - t0, "seconds process time")
报错:
1.错误信息:AttributeError: module ‘time’ has no attribute ‘clock’。
2.错误分析:在python3.8中,time模块下不支持clock,改成time.perf_counter()即可解决错误。
3.修改如下:
import time
a = []
t0 = time.perf_counter()
for i in range(1,1000):
a.append(i)
print(time.perf_counter() - t0, "seconds process time")
运行结果: