分享

成功解决AttributeError: module ‘time‘ has no attribute ‘clock‘

 处女座的程序猿 2023-04-12 发布于上海

解决问题

AttributeError: module 'time' has no attribute 'clock'

解决思路

属性错误:模块'time'没有'clock'属性

解决方法

在Python 3.8及以后的版本中,time.clock()函数已被删除。该函数曾经返回处理器时间,这并不是实际经过的时间,而是当前进程使用的CPU时间。以后,我们可以使用time.perf_counter()函数来获取当前的CPU时间,或者使用time.process_time()函数来获取当前进程使用的CPU时间。import time start_time = time.perf_counter() # some code to measure execution time end_time = time.perf_counter() print("Execution time:", end_time - start_time)

将time.clock()

改为time.perf_counter

大功告成!

    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多