Re: instance attributes not inherited?



David Hirschfield wrote:
Nothing's wrong with python's oop inheritance, you just need to know that the parent class' __init__ is not automatically called from a subclass' __init__. Just change your code to do that step, and you'll be fine:

class Parent( object ):
    def __init__( self ):
        self.x = 9


class Child( Parent ): def __init__( self ): super(Child,self).__init__() print "Inside Child.__init__()"

-David


How does it help that Parent.__init__ gets called? That call simply would create a temporary Parent object, right? I don't see how it should help (even though it *does* indeed work).

Why do we need to pass self along in that call to super()? Shouldn't
the class name be enough for super() to find the right superclass object?
.



Relevant Pages

  • Re: super with block
    ... through" to the parent class. ... def gsub! ...
    (comp.lang.ruby)
  • super with block
    ... through" to the parent class. ... class Nstring < String ... def gsub! ...
    (comp.lang.ruby)
  • Re: how do I pass values between classes?
    ... Each subclass are saved in seperate file and all my ... subclasses and parent class are placed in the same folder. ... Please tell me whether I am following a correct method, by fragmenting ... def OnBrowse: ...
    (comp.lang.python)
  • Re: How "Super" is implemented by Java?
    ... "super" is resolved/implemented in java (or for that matter any OO ... a Dachshund, you have also instantiated a Dog, a Mammal, an Animal, ... variables and methods of the parent class in the object of a child ...
    (comp.lang.java.help)
  • Re: How "Super" is implemented by Java?
    ... from the parent class was point in question. ... > referencing through the "super" keyword and without it? ... What the JVM or compiler does is search the linked list. ...
    (comp.lang.java.programmer)