OO issues in python

Michael T. Babcock mbabcock at fibrespeed.net
Wed Dec 17 22:41:15 CET 2003

> in python, when a class, say Father, has a member that itself is an 
> instance of another class, say Child, an instance of Father actually 
> only has a reference to a Child, not the Child object itself, right? 

I've seen a few responses to this but I wanted to point something out 
... an instance of the Father will not know about the Child at all.

class Father:

class Child(Father):

f = Father()
# f knows nothing about Child

However, the rest of your message sounds like "how do I do virtual 
functions?" to me ... you're aware that you can replace parent 
functions, correct?

class Father:
    def run(self):
       '''run the function; used in children'''

    def __init__(self):
       '''this is stupid but its just an example'''

class Child(Father):
    def run(self):
       '''child version of the run function'''

       print "Hello"

 >>> c = Child()

Michael T. Babcock
C.T.O., FibreSpeed Ltd.

More information about the Python-list mailing list