AttributeError: module time has no attribute clock
时间: 2023-09-27 07:08:20 浏览: 281
AttributeError: module 'tensorflow.compat.v1' has no attribute '
The error message "AttributeError: module time has no attribute clock" means that the "clock" attribute is not available in the "time" module.
The "clock" function was deprecated in Python 3.3 and removed in Python 3.8. Instead of using "time.clock()", you can use "time.perf_counter()" or "time.process_time()" depending on your use case.
Here's an example of using "time.perf_counter()" to measure the time taken for a piece of code to execute:
```
import time
start_time = time.perf_counter()
# Code to be timed
for i in range(1000000):
pass
end_time = time.perf_counter()
elapsed_time = end_time - start_time
print(f"Elapsed time: {elapsed_time:.6f} seconds")
```
阅读全文