timeit.py examples in docs generate error
duncan.booth at invalid.invalid
Thu Mar 9 20:16:49 CET 2006
> I was reading the thread on try/except overhead and decided to try
> Alex's examples but they kept generating exceptions. So I went to the
> docs and tried the examples there (copied and pasted) with the same
> results (Win2k, Python 2.4). Any help is appreciated. The output
> follows: #1
> C:\Python24\Lib>timeit.py 'if hasattr(int, "__nonzero__"): pass'
> Traceback (most recent call last):
> File "C:\Python24\Lib\timeit.py", line 285, in ?
> File "C:\Python24\Lib\timeit.py", line 249, in main
> t = Timer(stmt, setup, timer)
> File "C:\Python24\Lib\timeit.py", line 116, in __init__
> code = compile(src, dummy_src_name, "exec")
> File "<timeit-src>", line 6
> SyntaxError: EOL while scanning single-quoted string
Window's command processor doesn't recognise single quote marks as
meaning anything special, so your command is passing 4 separate arguments
to timeit.py instead of the 1 argument that a unix shell would be passing.
Try using double quotes around everything instead:
timeit.py "if hasattr(int, '__nonzero__'): pass"
More information about the Python-list