Right now I use the parameter object's class to be inherited like so
class A():
def __init__(self,p1,p2):
self.p1, self.p2 = p1, p2
class B(A):
def __init__(self,b):
self.p1, self.p2 = b.p1, b.p2
This trims up the absurdity of using the code but not the class code itself. So, I'd like to do the C++ thing and pass the parameter object to the initialization list like so
class A {
int p1,p2;
}
class B : public A {
B(const A& a) : A(a) {}
}
Can I do this in Python? Specifically, can I set the attributes of a parent class by somehow calling it's __init__
within the child's? - from reading "Dive into Python" I'd guess I can do this since the object is already constructed by the time __init__
is called.
Or, perhaps is there some different method of implementing the parameter object refactor in Python (and I'm just trying to force a C++ technique)?