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\Li b\timeit.py", line 285, in ?
sys.exit(main() )
File "C:\Python24\Li b\timeit.py", line 249, in main
t = Timer(stmt, setup, timer)
File "C:\Python24\Li b\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\Li b\timeit.py", line 285, in ?
sys.exit(main() )
File "C:\Python24\Li b\timeit.py", line 249, in main
t = Timer(stmt, setup, timer)
File "C:\Python24\Li b\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 2 1772
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\Li b\timeit.py", line 285, in ? sys.exit(main() ) File "C:\Python24\Li b\timeit.py", line 249, in main t = Timer(stmt, setup, timer) File "C:\Python24\Li b\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"
"Duncan Booth" <du**********@i nvalid.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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", "copyright", "credits" or "license" for more information.
>>> import timeit
>>> import time
>>> t=timeit.Timer("pass","pass",time.time)
>>> print t.timeit()
|
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()
|
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"
|
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 of its documentation, it is a
impeccability.
it has or possesses properties of:
|
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 = t.timeit()
| |
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 to use from the command line, but it is less convenient for
timing large pieces of code or when working in the interactive
interpreter. E.g. variations on this *don't* work:
$ python
Python 2.4.3 (#1, Jun 13 2006, 11:46:08)
|
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( setup="from Createlst import createlst", stmt=
|
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 = timeit.Timer("callFunc(line, i)","from __main__
|
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 in a class?
class FetchUrlThread(threading.Thread):
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |