如何使用导入时间库在Python中实现Clock()方法?

发布于 2025-02-08 03:02:55 字数 424 浏览 1 评论 0原文

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)

时间库具有一个有效的方法,称为clock()。但是当我运行代码时,我会收到一个错误:

attributeError:模块'time'没有属性'时钟'

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'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

以酷 2025-02-15 03:02:55

来自 python 3.8 的新事物

函数时间.clock()已被删除
自Python 3.3以来弃用:使用time.perf_counter()或
time.process_time()而不是根据您的要求
定义明确的行为。

time.Clock未始终如一地实现,新的API旨在涵盖其各种用途。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文