Reputation: 23
I have a small python program written for python 2.7.3:
import time
def fun():
print('Hi')
for i in range(3):
Timer(i, fun).start()
When I run it, I get the error:
NameError: name 'Timer' is not defined
How can I find out which module supports this functionality?
Upvotes: 0
Views: 11009
Reputation: 50540
You are looking for the timeit module. You can use your existing code by replacing your current import:
from timeit import Timer
Upvotes: 0
Reputation: 720
Timer
is in the timeit
module, not time
. And to call it like you want to, you would have to from timeit import Timer
, not just import timeit
. If you just declare import timeit
, then you would have to write timeit.Timer
instead of Timer
everywhere in the code.
Upvotes: 5