Hi,

I want to create an array of functions, each doing the same thing with a
change to the parameters it uses... something like:

arr=['john','terry','graham']

funcs=[]

for name in arr:

                def func():

                                print 'hello, my name is '+name

                funcs.append(func)

for f in funcs:

                f()

 

And I would like that to print

hello, my name is john

hello, my name is terry

hello, my name is graham

of course... 

Now I understand why the above code doesn't work as I want it to, but is
there some simple workaround for it? 

Thanks, Noam 

 

 

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to