I have a problem with objects.
The following code
class Data:
def __init__(self,data=[]):
self.data = data
def add(self,data):
self.data.extend(data)
class Parent:
def testa(self):
a = Data()
a.add('a')
print a.data
def testb(self):
b = Data()
b.add('b')
print b.data
if __name__ == "__main__":
p = Parent()
p.testa()
p.testb()
Generates the following output:
[]
['a']
['a']
['a', 'b']
Why is there not a new object created? The second time in testb it seems that the old Data object still exists, although it was in a private variable.
How can I change the code so that a new object is created?