Re: instance attributes not inherited?
- From: "John M. Gabriele" <john_sips_teaz@xxxxxxxxxx>
- Date: Sun, 15 Jan 2006 20:37:36 -0500
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? .
- Follow-Ups:
- Re: instance attributes not inherited?
- From: Bengt Richter
- Re: instance attributes not inherited?
- From: Dan Sommers
- Re: instance attributes not inherited?
- From: John M. Gabriele
- Re: instance attributes not inherited?
- References:
- instance attributes not inherited?
- From: John M. Gabriele
- Re: instance attributes not inherited?
- From: David Hirschfield
- instance attributes not inherited?
- Prev by Date: Re: How to get Windows system information?
- Next by Date: Re: New Python.org website ?
- Previous by thread: Re: instance attributes not inherited?
- Next by thread: Re: instance attributes not inherited?
- Index(es):
Relevant Pages
|