[Tutor] What's the problem with my SpinSpeeds.py?

Alan Gauld alan.gauld at blueyonder.co.uk
Sun Aug 1 20:10:41 CEST 2004


> Why am I unable to use countUsingRange(n) instead of
countUsingRange(25000)?

Because you are passing a string into the timer. The timer tries to
parse the string but doesn't have access to n internally.

You could use n if you created the string using a format operator:

> if __name__=='__main__':
>      from timeit import Timer
>      repetitions = 1000
>      n = 25000
>
       cmd = "countUsingRange(%d)" % n
>      t = Timer(cmd, "from __main__ import countUsingRange")
>      rangeTime = t.timeit(repetitions)

HTH,

Alan G.



More information about the Tutor mailing list