I have TestData class where I want to store time, x, y info.
Then I have a GenericData class where I want two TestData instances saved as left and right.
I instantiate GenericData and I append a value to the left instance, but the right instance is also updated!
This means that when I call generic = GenericData(TestData(), TestData()) the two TestData() calls are instantiating the same object.
How can I instantiate two different TestData inside GenericData, so I can update them independently?
class GenericData:
def __init__(self, left, right):
self.left = left
self.right = right
class TestData:
def __init__(self, t=[], x=[], y=[]):
self.t = t
self.x = x
self.y = y
generic = GenericData(TestData(), TestData())
generic.left.t.append(3)
print(generic.left.t)
print(generic.right.t)
[3]
[3] <-- This one should be empty!