469,364 Members | 2,332 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,364 developers. It's quick & easy.

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

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!

Jan 19 '07 #1
1 1866
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#formattingand 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

Jan 19 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by rurpy | last post: by
11 posts views Thread by Russ | last post: by
44 posts views Thread by gokkog | last post: by
5 posts views Thread by yinglcs | last post: by
2 posts views Thread by kevin | last post: by
3 posts views Thread by silverburgh.meryl | last post: by
27 posts views Thread by idoerg | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.