oop - python __init__ method in inherited class -


i give daughter class attributes without having explicitly call new method. there way of giving inherited class __init__ type method not override __init__ method of parent class?

i have written code below purely illustrate question (hence poor naming of attributes etc).

class initialclass():     def __init__(self):         self.attr1 = 'one'         self.attr2 = 'two'      class inheritedclass(initialclass):     def __new__(self):         self.attr3 = 'three'      def somemethod(self):         print 'the method'   = inheritedclass()  each in a.__dict__:     print each  #i output be: attr1 attr2 attr3 

thank you

as far know that's not possible, can call init method of superclass, this:

class inheritedclass(initialclass):     def __init__(self):         initialclass.__init__(self)         self.attr3 = 'three' 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -