[Tutor] Classes + inheritance

Arne Mueller a.mueller@icrf.icnet.uk
Fri, 16 Apr 1999 16:08:02 +0100


Hi All (again ...),

first of all: thanks very much with help on 'long statements'

and now to something completely different ...:
I've written a modul 'blast.py' which defines some classes (e.g. Blast,
Iteration).

A program test.py uses this modul

import sys
from blast import *

and defines it's own version of class 'iteration' (in file test.py)

class Iteration(Iteration):
    
    def __init__(self, f):
        sys.stderr.write('My redefined class Iteration ...')
        Iteration.__init__(self, f)

    def parseBlock(self, token):
        sys.stderr.write('My redefined parseBlock ...')
        return

I create an obejct of class Blast

f = IO('myfile', 'r', 100) # create an io object
b = Blast(f)               # create an empty blast object
b.createBlastTree()        # do something on it ...

and call a method of that object (createBlastTree). This method
(internally) creates several objects of class 'Iteration' (but class
Blast does NOT inherit from class Iteration). I want to change the
behaviour of several functions of the 'Iteration' class, so in my
program I define a new version of class Iteration (see above) - but it
turned out that b.createBlastTree() still creates objects of the old
Iteration class! 

Confusing ??? Hm, I'm confused. How can I make b.createBlastTree() using
the redefined/extended version of 'Iteration' without modifying the
source in modul 'blast.py'. THese extension are program specific, and I
intended to use inheritance to cope with the problem - alas, it doesn't
seem to work :-( . 

So, now tell me that I'm completely wrong, and that all my work of the
last 3 days cannot work because I misunderstood python's object
orientation :-(((((

	sorry for frequently asking question ;-),

	Arne