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

Discussion in 'Python' started by Dongsheng Ruan, Jan 19, 2007.

  1. 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!
    Dongsheng Ruan, Jan 19, 2007
    #1
    1. Advertising

  2. Re: How to pass arguments to the function embedded in thetimeit.Timer()

    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
    Gabriel Genellina, Jan 19, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dan Christensen
    Replies:
    4
    Views:
    562
    Peter Otten
    Jul 14, 2004
  2. Replies:
    2
    Views:
    264
  3. Replies:
    3
    Views:
    324
  4. jmborr
    Replies:
    1
    Views:
    401
    Stargaming
    Nov 3, 2007
  5. ssecorp
    Replies:
    5
    Views:
    305
    Steven D'Aprano
    Aug 4, 2008
Loading...

Share This Page