473,406 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

timeit.py examples in docs generate error

Hello,
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 ?
sys.exit(main())
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
'if
^
SyntaxError: EOL while scanning single-quoted string

#2
C:\Python24\Lib>timeit.py 'try:' ' str.__nonzero__' 'except
AttributeError:' '
pass'
Traceback (most recent call last):
File "C:\Python24\Lib\timeit.py", line 285, in ?
sys.exit(main())
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 7
'
^
SyntaxError: EOL while scanning single-quoted string

Thanks again,
Louis
Mar 9 '06 #1
2 1759
3c273 wrote:
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 ?
sys.exit(main())
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
'if
^
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"

Mar 9 '06 #2
"Duncan Booth" <du**********@invalid.invalid> wrote in message
news:Xn*************************@127.0.0.1...
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"

That did the trick. Thanks!
Louis
Mar 9 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dan Christensen | last post by:
The test below is done with Python 2.4a1 compiled from source, but the same thing happens with Debian's python2.3_2.3.4-2. Python 2.4a1 (#1, Jul 11 2004, 12:20:32) on linux2 Type "help",...
2
by: Roy Smith | last post by:
I'm playing with the timeit module, and can't figure out how to time a function call. I tried: def foo (): x = 4 return x t = timeit.Timer ("foo()") print t.timeit()
5
by: rurpy | last post by:
Why doesn't the following work? It generates a "NameError: global name 'data' is not defined" error. import timeit global data data = env = "global data; x = data"
102
by: Xah Lee | last post by:
i had the pleasure to read the PHP's manual today. http://www.php.net/manual/en/ although Pretty Home Page is another criminal hack of the unix lineage, but if we are here to judge the quality...
2
by: Steven D'Aprano | last post by:
When using the timeit module, you pass the code you want to time as strings: import timeit t = timeit.Timer("foo(x, y)", \ """from module import foo x = 27 y = 45 """) elapsed_time =...
2
by: Steven D'Aprano | last post by:
The timeit module is ideal for measuring small code snippets; I want to measure large function objects. Because the timeit module takes the code snippet argument as a string, it is quite handy...
1
by: Dongsheng Ruan | last post by:
Hi Does anybody know how to pass multiple arguments to the function tested in timeit.timer() in python? I googled and found how to pass one argument: x=10000 mytime = timeit.Timer(...
3
by: silverburgh.meryl | last post by:
Hi, I have a function in my python like this: def callFunc(line, no): # some code And I want to do a performance test like this: for line in f: for i in range(int(count)): t1 =...
7
by: silverburgh.meryl | last post by:
Hi, I am using timeit to time a global function like this t = timeit.Timer("timeTest()","from __main__ import timeTest") result = t.timeit(); But how can i use timeit to time a function...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.