I'm working with multiple classes that share some initial common variables/attributes. In order to make it cleaner and avoid calling the same variables multiple times I want to set them all in an initial class (e.g. classA) and then load all this attributes in a classB.
So I would define:
class classA:
def __init__(self, varA, varB, varC, ..., varZ):
self.varA = varA
self.varB = varB
self.varC = varC
(...)
self.varZ = varZ
And then load it in a second classB
class classB:
def __init__(self, classA):
self.varA = classA.varA
self.varB = classA.varB
self.varC = classA.varC
(...)
self.varZ = classA.varZ
Is there a better way to make this happen, without going over all the individual attributes?
class classB(classA)?classBis fully derived fromclassA, you could inheritBfromAlike Rakesh suggests. If it shares only some attributes, you could have a common base classclassCommonand have bothclassAandclassBinherit from that oneclassB, instead of just callingclassB(classA)in the script.