I have a problem in my current project and i narrowed down the problem to this.
I want this output: 0, 1, 2, 3, 4, 5, ...
But my output: 9, 9, 9, 9, 9, 9, ...
class Foo:
def __init__(self, command):
self.command = command
listOfFoos = []
for i in range(10):
listOfFoos.append(Foo(command=(lambda: print(i))))
for foo in listOfFoos:
foo.command()