I have two scripts, one where a class is created and a second loading/plotting script. I have three instances of the same class (T1
, T2
, and T3
) but want to combine them into a single T
. When do T=T1
, then T+T2
and T+T3
, T1
inherits the T2
and T3
instances when I only want T
to have all the instances.
I tried modifying my __add__
magic method in my class script as below but the deepcopy
doesn't work. The T
continues to be empty. However when I do T = deepcopy(T1)
in my command window, it works fine. I'd prefer the __add__
method to include this capability.
From class script:
def __add__(self, other):
""" A "magic" method to overload the '+' operator by
appending trajectories.
"""
if len(self.contents) == 0:
self = deepcopy(other)
else:
self.contents.append(other)
I also tried created a new method to directly do the deepcopy, but it also will not copy as expected.
def copy(self,other):
self = deepcopy(other)
I start with T
empty:
In [80]: T.contents
Out[80]: []
But I want T
to include T1
through T3
without T1
being identical to T
.
In [74]: T.contents
Out[74]:
[Trajectory Object: MONTE_RUN_mmv13_2D2M_RODupdate
contains data from FAST,
Trajectory Object: MONTE_RUN_mmv13_1D2M_RODupdate
contains data from FAST,
Trajectory Object: MONTE_RUN_mmv13_2D3M
contains data from FAST]
Not:
In [74]: T1.contents
Out[74]:
[Trajectory Object: MONTE_RUN_mmv13_2D2M_RODupdate
contains data from FAST,
Trajectory Object: MONTE_RUN_mmv13_1D2M_RODupdate
contains data from FAST,
Trajectory Object: MONTE_RUN_mmv13_2D3M
contains data from FAST]