python 报错 AttributeError: module ‘time‘ has no attribute ‘clock 解决方法

比眉伴天荒 2021-09-07 06:02 2154阅读 1赞

源码如下:

  1. #引入所需要的时间库
  2. import datetime
  3. import time
  4. #程序计时器,启动计时器
  5. start = time.clock()
  6. #中间是放置需要测试运行时间的程序代码
  7. #计算启动时间和结束时间的时间差
  8. end = time.clock()
  9. print('运行时间 : %s 秒'%(end-start))

报错 AttributeError module ‘time’ has no attribute ‘clock’

解决方法:python3.8不支持 clock 了,用 time.perf_counter() 替换就可以了

发表评论

表情:
评论列表 (有 0 条评论,2154人围观)

还没有评论,来说两句吧...

相关阅读