I have multiple python classes. Objects of one of the classes (say, class1)has a large amount of data in it (it will not be altered during runtime). Another class (say class2) has a member variable which maps to one of the objects of class1. Assume class1 and class2 have other both mutable and immutable member variables.
Now i want too do a deepcopy of an object of class2. It will also make a deepcopy of the class1 object in class2. but to save memory, i want to avoid that. how do i do this?
class class1:
def __init__(self):
self.largeData = None
self.mutableVar = None
self.immutableVar = None
class class2:
def __init__(self, objc1: class1):
self.objc1 = objc1 # of the type class1
self.mutableVar = None
self.immutableVar = None
c1_1 = class1()
c1_2 = class1()
c2_1 = class2(c1_1)
c2_1Copy = copy.deepcopy(c2_1)
# i want c2_1Copy to reference the same objc1 as c2_1,
# but different mutablevar and immutablevar
c2_2 = class2(c1_2) # Note: cannot use static variable
please help me with this...
thanks in Advance
copyanddeepcopyinclass2. See Best practice to implement copy method - Error - Syntactical Remorse__deepcopy__as to not copy some members for that class. - Dan D.