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

Dongsheng Ruan ruan at jcmills.com
Thu Jan 18 19:31:20 EST 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!






More information about the Python-list mailing list