Python3.8 異常AttributeError module 'time' has no attribute 'clock'

出現異常:

在pycharm中加Python3.8環境,調用time.clock出異常:AttributeError module 'time' has no attribute 'clock'

經過度娘,其原因:

Python3.8不再支持time.clock,但在調用時依然包含該方法;

有效處理:

用time.perf_counter()替換

import time
tis1 =time.perf_counter()
print("等待5秒......")
time.sleep(5)
tis2=time.perf_counter()
print(tis2-tis1)
等待5秒......
4.999518311

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章