Warning: session_start(): open(/tmp/sess_bfff7730ddb8a26bbccc00797e417431, O_RDWR) failed: Disk quota exceeded (122) in /home/wvyrfnwn/learnshareit.com/wp-content/plugins/learnpress/inc/class-lp-page-controller.php on line 1007

Warning: session_start(): Failed to read session data: files (path: /tmp) in /home/wvyrfnwn/learnshareit.com/wp-content/plugins/learnpress/inc/class-lp-page-controller.php on line 1007

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 719

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 719

Warning: ftp_mkdir() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 562

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230
How To Solve Error "AttributeError Module 'Time' Has No Attribute 'Clock'" In Python - LearnShareIT

How To Solve Error “AttributeError Module ‘Time’ Has No Attribute ‘Clock'” In Python

AttributeError module ‘time’ has no attribute ‘clock’

The error “AttributeError: module ‘time’ has no attribute ‘clock'” happens because the function time.clock() has been removed in Python 3.8 or later. To fix the error, let follow the article below

AttributeError module ‘time’ has no attribute ‘clock’

In Python 3.8 or later

Example: 

import time
print(time.clock())

Output:

Traceback (most recent call last):
  File "./prog.py", line 2, in <module>
AttributeError: module 'time' has no attribute 'clock'

How to solve this error?

Use time.time() function

You can replace all statements where the time.clock() function occurs with the time.time() function in the code.

Example:

  • Import module time
  • The time.time() function will return the detailed time to the number of seconds.
import time

# The time.time() function will return the detailed time to the number of seconds
startTime = time.time()
print(startTime)

# Stops execution of the current thread within seconds passed.
time.sleep(2)

# The time.time() function will return the detailed time to the number of seconds.
endTime = time.time()
print(endTime)

print("Elapsed Time: ", endTime - startTime)

Output:

1664592364.2982788
1664592366.3102856
Elapsed Time: 2.0120067596435547

Function calculated the elapsed time without program error.

Use functions instead of time.clock()

If you are using Python versions 3.8 and earlier, you can use the following functions to replace the time.clock() function:

  • time.perf_counter()
  • time.process_time()

The time.process_time() and time.perf_counter() functions provide the same results as the time.clock() function, which was removed in Python 3.8 and later.

The time.perf_counter() function returns the value in fractional seconds of the coefficient counter. It will include the time elapsed during sleep and on the whole system.

Example:

import time

startTime = time.perf_counter()
print(startTime)

time.sleep(2)
endTime = time.perf_counter()
print(endTime)
print("Elapsed Time: ", endTime - startTime)

Output:

24912350.81560414
24912352.816202506
Elapsed Time: 2.00059836730361

The time.process_time() function is a time processing function that does not include I/O operations, network density, and latency in the computation process. The time.process_time() function returns a float value of the time in seconds. It will not include sleep time like the time.perf_counter() function.

Example:

import time

startTime = time.process_time()

for i in range(10):
    print(i, end=' ')

print(startTime)
endTime = time.process_time()

print(endTime)
print("Elapsed Time : ", endTime - startTime)

Output:

0 1 2 3 4 5 6 7 8 9 0.016585886
0.016599327
Elapsed Time : 1.3440999999999453e-05

In other words, the process_time() function calculates the CPU time at the current process.

Replace module

If you are using the PyCrypto module, I recommend removing it and installing the pycryptodome module. Since the pycryptodome module is more actively supported.

Example:

pip3 uninstall PyCrypto
pip3 install -U PyCryptodome

Downgrade the version of Python you are using

Downgrading your Python version is probably not the best way to do it, but if the new Python versions make you feel uncomfortable, go for it. It might help you write smoother code.

Maybe you are interested in similar errors:

Leave a Reply

Your email address will not be published. Required fields are marked *