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):
> >
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
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
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
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
>>>