Re: parameters to lambda's executed at run time.

2008-05-06 Thread castironpi
On May 6, 5:17 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > wyleu wrote: > > I'm trying to supply parameters to a function that is called at a > > later time as in the code below: > > > llist = [] > > > for item in range(5): > >     llist.append(lambda: func(item)) > > > def func(item): > >

Re: parameters to lambda's executed at run time.

2008-05-06 Thread Marco Mariani
Boris Borcic wrote: One way : >>> from functools import partial >>> def func(item) : print item >>> llist = [partial(func,item) for item in range(5)] >>> for thing in llist : thing() 0 1 2 3 4 Another way: class Func(object): def __init__(self, item): self.item = item

Re: parameters to lambda's executed at run time.

2008-05-06 Thread Boris Borcic
One way : >>> from functools import partial >>> def func(item) : print item >>> llist = [partial(func,item) for item in range(5)] >>> for thing in llist : thing() 0 1 2 3 4 wyleu wrote: I'm trying to supply parameters to a function that is called at a later time as in the code below: llist

Re: parameters to lambda's executed at run time.

2008-05-06 Thread Diez B. Roggisch
wyleu wrote: > I'm trying to supply parameters to a function that is called at a > later time as in the code below: > > llist = [] > > for item in range(5): > llist.append(lambda: func(item)) > > def func(item): > print item > > for thing in llist: > thing() > > which produces the

parameters to lambda's executed at run time.

2008-05-06 Thread wyleu
I'm trying to supply parameters to a function that is called at a later time as in the code below: llist = [] for item in range(5): llist.append(lambda: func(item)) def func(item): print item for thing in llist: thing() which produces the result IDLE 1.2.1 >>>