AttributeError module ‘time‘ has no attribute ‘clock‘ 解决方法

AttributeError module ‘time‘ has no attribute ‘clock‘ 解决方法

再度Miren
2021-03-02 / 0 评论 / 307 阅读 / 正在检测是否收录...


一、问题

在 Pycharm + Python3.8 环境中,调用 time.clock() 报错:AttributeError: module ‘time’ has no attribute ‘clock’,可 Pycharm 中的代码提示是有这个方法的,但运行调用这个方法就报错,好家伙!

二、解决方法

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

我们可以用 time.perf_counter() 来替换即可,然后可以正常使用计时,如下图所示:


0

评论 (0)

取消