-2
import time

print(chr(27) + "[2J") # Somehow this clears the console??
print("*************************") 
# Get the current processor
# time in seconds
program_time = time.clock()
  
# print the current 
# processor time
print("Current processor time (in seconds):", program_time)

The time library has a valid method called clock(). But when I run the code I get an error:

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

Dharman
  • 30,962
  • 25
  • 85
  • 135
SiO
  • 21
  • 1
  • 5
  • 1
    Where do you see time.clock() in the [documentation](https://docs.python.org/3/library/time.html)? – Anon Coward Jun 16 '22 at 18:02
  • It looks like `time.clock` was deprecated in python 3.3 and removed in python 3.8 – jprebys Jun 16 '22 at 18:07
  • Yeah - in the docs it says `Deprecated since version 3.3, will be removed in version 3.8: The behaviour of this function depends on the platform: use perf_counter() or process_time() instead, depending on your requirements, to have a well defined behaviour.` – The Thonnu Jun 16 '22 at 18:08
  • this is the link: https://stackoverflow.com/questions/59037251/changing-fps-on-pygame-in-order-to-achieve-smoothness-of-sprites-movement – SiO Jun 16 '22 at 21:04
  • @AnonCoward - time.clock has been around for a long time. That it was removed in 3.8 doesn't mean that examples using clock somehow went away. It may be more constructive to point out what happened than taking swipes at the poster. – tdelaney Jun 21 '22 at 18:08
  • I wasn't taking a swipe at the poster? I was confused, because they were attempting to use an undocumented API. – Anon Coward Jun 21 '22 at 18:27

1 Answers1

0

From What’s New In Python 3.8

The function time.clock() has been removed, after having been deprecated since Python 3.3: use time.perf_counter() or time.process_time() instead, depending on your requirements, to have well-defined behavior.

time.clock was not implemented consistently cross-platform and the new API is meant to cover its various uses.

tdelaney
  • 73,364
  • 6
  • 83
  • 116