Here I have some python code. A loop creates an object with non-binding paramerters.
The first time everything works normally.
In the second run, however, the attribute of the last object created is used as the parameter.
This works with the dictionary because it is stored in the heap.
How do I make sure that if no parameters are specified, they are not read from the heap?
class ClassXY:
def __init__(self, variables={}):
print(variables)
self.variables = variables
self.variables["key"] = "xyz"
for i in range(3):
ClassXY()
The output:
{}
{'key': 'xyz'}
{'key': 'xyz'}
The output I want:
{}
{}
{}
Thank you :D