class parenting basic

It is pointless to make C.__init() explicitly call B.init().

If class C is derived from class B, then instantiating an object using
class C will automatically call C.init(), which in turn will
automatically call B.init.

Also, to help keep your sanity, define all the classes first then put
the real-time code at the bottom.

Class A is unused in your second example, so delete it - it just
confuses thing.

For now, just pass value objects as parameters rather than class objects.

Ray Pasco

`#----------------------------

class B():

def __init__( self, val ):

    

    self.val = val

    self.internalVal = 'BbB'

    print

    print "----  B __init__ argumentval is %s" % (self.val)

    print "----  B __init__ internalVal is %s" % (self.internalVal)

    

#end __init B



def PrintMyVal( self ) :

    print

    print '----  B.val  is %s' % (self.val)

    print '----  B.valB is %s' % (self.internalVal)

#end PrintMyVal def

#end B class

``#----------------------------

``class C( B ):

def __init__( self, val ):



    self.val = val

    self.internalVal = 'CcC'

    print

    print "----  C __init__ argumentval is %s" % (self.val)

    print "----  C __init__ internalVal is %s" % (self.internalVal)

    

    self.instB = B( 'BBB' )

    

#end __init C



def PrintMyVal( self ) :

    print

    print '----  C.val              is %s' % (self.val)

    print '----  C.internaVal       is %s' % (self.internalVal)

    print '----  C.instB.val        is %s' % (self.instB.val)

    print '----  C.instB.intenalVal is %s' %

(self.instB.internalVal)

#end PrintMyVal def

#end C class

···

#----------------------------

instC = C( ‘CCC’ )

instC.PrintMyVal()

instC.instB.PrintMyVal()

#----------------------------

`

No it doesn't.

In your example you don't initialize B as a base class of the C instance, but instead create a new instance of B. In other words, in your code C "has-a" B instead of the "is-a" relationship that would be expected because of the inheritance.

···

On 7/13/10 9:39 AM, Ray Pasco wrote:

It is pointless to make C.__init() explicitly call B.__init__().

If class C is derived from class B, then instantiating an object using
class C will automatically call C.__init__(), which in turn will
automatically call B.__init__.

--
Robin Dunn
Software Craftsman