mutlifile inheritance problem simplified

Marc maurelius01 at hotmail.com
Fri Mar 22 17:08:55 EST 2002


I posted this previously but a typo confused the
issue.  I'll be more carefull this time, plus I've
simplified the names.

The issue has to do with using reload and
inheritance, specifically having two classes in
two different files inheriting from a base class
in another file.  Or maybe it's just inheriting
and reloading, I haven't gone through the many
permutations, but here's a simple example that
doesn't work.

I'm using Windows NT, Python 1.5.2, and IDLE 0.5

************************
file a01.py

class a:

    def __init__(self):
        self.name  = 'a'

************************
file b01.py

import a01
reload(a01)
class b(a01.a):
    def __init__(self):
        self.name = 'b'
        a01.a.__init__(self)

************************
file c01.py

import a01
reload(a01)
class c(a01.a):
    def __init__(self):
        self.name = 'c'
        a01.a.__init__(self)


************************
file atest01.py

import b01
reload(b01)
import c01
reload(c01)

B = b01.b()
C = c01.c()
print 'done'

*************************
running atest01 (F5 in IDLE) give the traceback:
>>> 
Traceback (innermost last):
  File "<string>", line 1, in ?
  File
"D:\PythonCode\pna\eyeTracking\tests\atest01.py",
line 7, in ?
    B = b01.b()
  File
"D:\PythonCode\pna\eyeTracking\tests\b01.py", line
8, in __init__
    a01.a.__init__(self)
TypeError: unbound method must be called with
class instance 1st argument

If I don't have the reload in c01.py and b01.py
eveything works fine. 

Any ideas.  Does anyone else find the same
behavior here?

Thanks, Marc



More information about the Python-list mailing list