mutlifile inheritance problem

Peter Cacioppi peter.cacioppi at gmail.com
Fri Sep 20 20:17:03 EDT 2013


On Thursday, March 21, 2002 2:03:23 PM UTC-7, Marc wrote:
> I have classes defined in different files and would like to inherit
> from a class in file A.py for a class in file B.py but am running into
> problems.  I'm using Python 1.5.2 on Windows NT
> 
> Here's a specific example:
> 
> ************************
> file cbase01.py:
> 
> class CBase:
> 
>     def __init__(self):
>         self.cclass = None
>         print "cbase"
> 
> class CImStream(CBase):
> 
>     def __init(self):
>         CBase.__init__(self)
>         print "CImStream"
> 
> *************************
> in file wrappers_A01.py: 
> 
> import cbase01
> reload(cbase01)
> 
> class ImStream_SavedBitmaps(cbase01.CImStream):
> 
>     def __init__(self):
>         cbase.CImStream.__init__(self)
>         print "SavedBitmaps"
> 
> **************************
> in file sequencer01.py
> 
> import cbase01    # the offending lines, program works 
> reload(cbase01)   # if I comment these out.
> 
> class Sequencer:
> 
>     def Append(self, item):
>         pass
> 
> *****************************
> in test02.py
> 
> import wrappers_A01
> reload(wrappers_A01)
> 
> import sequencer01
> reload(sequencer01)
> 
> x0 = wrappers_A01.ImStream_SavedBitmaps()
> ***************************************************************
> 
> If I run test02 I get the traceback
> 
> Traceback (innermost last):
>   File "<string>", line 1, in ?
>   File "D:\PythonCode\pna\eyeTracking\tests\test02.py", line 15, in ?
>     x0 = wrappers_A01.ImStream_SavedBitmaps()
>   File "D:\PythonCode\pna\eyeTracking\tests\wrappers_A01.py", line 21,
> in __init__
>     cbase.CImStream.__init__(self)
> TypeError: unbound method must be called with class instance 1st
> argument
> 
> 
> Any ideas what I am doing wrong?
> 
> Thanks,
> Marc

Yes my post has a mistake re: polymorphism. It seems self.__class__, whether called directly or indirectly, is always going to refer to the parent of the instance class. My code works only if there are no grandparents.


Bummer, but glad to learn something new.

It's too bad, I really lean on reload(). It appears to be incompatible with inheritance more than one level deep.




More information about the Python-list mailing list