I have the following code:
funcs = []
for i in range(10):
def func():
print i
funcs.append(func)
for f in funcs:
f()
The problem is that func
is being overriden. Ie the output of the code is:
9
9
9
...
How would you solve this without defining new functions?
The optimal solution would be to change the name of the function. Ie:
for i in range(10):
def func+i():
...
(or some other weird syntax)