Possible Duplicate:
Local variables in Python nested functions
Here is my problem, I need to create functions dynamically in python. I have a list in parameter and I need to create a function for each element of this list.
Here is an example :
list_func = []
list_param = ['foo','bar']
for param in list_param:
def print_func():
print(param)
list_func += [print_func]
for func in list_func:
func()
with this code the second loop will just print the last parameter. Here is the output :
bar
bar
I need
foo
bar
Thanks