I have been unable to find any questions on this or maybe I am using the wrong nomenclature in my search. If I have something like:
class testone(object):
def __init__(self):
self.attone = None
self.atttwo = None
self.attthree = None
class testtwo(testone):
def __init__(self):
self.attfour = None
And I do:
a = test()
print dir(a)
b = testtwo()
print dir(b)
One can see that a
will have all of it's attributes defined as None
but b
will only have attfour
defined even though it inherited class testone
. I understand this, but is it possible to make b
have all of the attributes inherited from a
implicitly defined as well at instantiation ?
I ask b/c I have classes that have tens of attributes that are inheriting from classes with hundreds of attributes and I need every attribute to be defined even if it is of type None
so that I don't have to worry about checking if the attribute exists before mapping it from my object to a database table. I am trying not to write as much code. If there is a way to do this then I save well over a thousand lines of code in my class definitions or I could just verify if each attribute exists before mapping the object to my table but that's a lot of code as well as I have a couple thousand attributes to check.