Python3.8 异常AttributeError module ‘time’ has no attribute ‘clock’-泓源视野

Python3.8 异常AttributeError module ‘time’ has no attribute ‘clock’

原由:time.clock() 自从python3.3之后就被废除

出现异常:

在pycharm中加Python3.8环境,调用time.clock出异常:AttributeError module 'time' has no attribute 'clock'

经过度娘,其原因:

Python3.8不再支持time.clock,但在调用时依然包含该方法;

有效处理:

用time.perf_counter()替换

  1. import time
  2. tis1 =time.perf_counter()
  3. print("等待5秒......")
  4. time.sleep(5)
  5. tis2=time.perf_counter()
  6. print(tis2-tis1)
  1. 等待5秒......
本文由 泓源视野 作者:admin 发表,其版权均为 泓源视野 所有,文章内容系作者个人观点,不代表 泓源视野 对观点赞同或支持。如需转载,请注明文章来源。
30

发表评论

Protected with IP Blacklist CloudIP Blacklist Cloud
您是第8238074 位访客, 您的IP是:[23.20.51.162]