[Tutor] timeit at the command line
Kent Johnson
kent37 at tds.net
Tue Oct 3 14:54:56 CEST 2006
Dick Moores wrote:
> Very interesting. I thought a line of that template looked familiar.
> I was seeing "_t0 = _timer()" regularly when I had the -s option set
> without any setup:
>
> C:\>python -m timeit -r 3 -s"for x in range(10000):" " x*x"
> Traceback (most recent call last):
> File "E:\Python25\lib\runpy.py", line 95, in run_module
> filename, loader, alter_sys)
> File "E:\Python25\lib\runpy.py", line 52, in _run_module_co
> mod_name, mod_fname, mod_loader)
> File "E:\Python25\lib\runpy.py", line 32, in _run_code
> exec code in run_globals
> File "E:\Python25\lib\timeit.py", line 285, in <module>
> sys.exit(main())
> File "E:\Python25\lib\timeit.py", line 249, in main
> t = Timer(stmt, setup, timer)
> File "E:\Python25\lib\timeit.py", line 116, in __init__
> code = compile(src, dummy_src_name, "exec")
> File "<timeit-src>", line 4
> _t0 = _timer()
> ^
> But I don't understand what the error has to do with _t0 . That's OK,
> don't bother to explain. I don't understand classes yet anyway.
> Should get into them soon, with Wes Chun's book.
If you substitute your code into the template by hand and look at the
actual exception (not shown above) you should see the problem. It
doesn't have anything to do with classes.
Kent
Kent
More information about the Tutor
mailing list