Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How to pass arguments to the function embedded in the timeit.Timer()

Reply
Thread Tools

How to pass arguments to the function embedded in the timeit.Timer()

 
 
Dongsheng Ruan
Guest
Posts: n/a
 
      01-19-2007
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=
"createlst(%s)"%(x) )

But how can I extend it to two or more arguments?

Like this:

p1=createlst.createlst(10000)
p2=createlst.createlst(10000)
mytime = timeit.Timer(setup="from list_concat_copy import list_concat_copy",
stmt="list_concat_copy.list_concat_copy(%x,%y)"%p1 ,p2 )

I don't know how to end the timeit.Timer. Should it be (%x,%y)"%p1,p2 or
(%x,%y)"%p1,%p2 or (%x,%y)"(%p1%p2) .

I tried and none worked. I just got error message like global variable "A'
not defined.

Can anybody help?

Thanks!



 
Reply With Quote
 
 
 
 
Gabriel Genellina
Guest
Posts: n/a
 
      01-19-2007
At Thursday 18/1/2007 21:31, Dongsheng Ruan wrote:

> 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=
>"createlst(%s)"%(x) )


This is the % operator for strings, and it's general, not related to
the timeit module.
You can find it explained in almost every tutorial. The "official"
tutorial explains it here:
<http://docs.python.org/tut/node9.html#formatting> and for more
detailed usage see here:
<http://docs.python.org/lib/typesseq-strings.html>

If you haven't already done it, I strongly recommend reading the
Python tutorial (you should find it inside your Python installation,
and you can read it online at <http://docs.python.org/tut/> )


--
Gabriel Genellina
Softlab SRL






__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Call again a variadic function (... variable number of arguments)with same arguments that its variadic wrapper moreau.steve@gmail.com C Programming 3 12-31-2008 07:13 AM
how to pass a function name and its arguments inside the arguments of other function? jmborr Python 1 11-03-2007 08:20 AM
function default arguments from other arguments tutmann C++ 4 10-17-2006 08:00 PM
function call with arguments which takes no arguments Neo C Programming 10 01-20-2005 06:31 AM



Advertisments