Ato*_*nge 0 python time nameerror python-3.x
我有一个为 python 2.7.3 编写的小型 python 程序:
import time
def fun():
print('Hi')
for i in range(3):
Timer(i, fun).start()
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我收到错误:
NameError: name 'Timer' is not defined
如何找出支持此功能的模块?
Timer在timeit模块中,而不是time. 并且要像您想的那样称呼它,您必须from timeit import Timer,而不仅仅是import timeit. 如果你只是声明import timeit,那么你将不得不在代码中写timeit.Timer而不是Timer到处。
| 归档时间: |
|
| 查看次数: |
7354 次 |
| 最近记录: |