advice on programming style: is multiple inheritance bad?

Uwe Mayer merkosh at hadiko.de
Tue Feb 3 09:57:24 EST 2004


Michael Hudson wrote:

> Uwe Mayer <merkosh at hadiko.de> writes:
> 
>> BTW: when doing m.i. you can't mix new-style and old-style objects, or
>> else Python exits with a Segmentation Fault. :)
> 
> Uhh, really?  Example please.

Seems only to occur in connection with Qt. :( 
Code as the one below, inheriting from some Qt Widget and using m.i. with
new-style classes cause a Segmentation Fault on my machine:

-- example --
from qt import QWidget, QApplication
import sys

class A:
    def __init__(self):
        print "in A"

class B(object):
    def __init__(self):
        print "in B"

class C(QWidget,A):
    def __init__(self):
        QWidget.__init__(self)
        A.__init__(self)
        print "in C"

class D(QWidget,B):
    def __init__(self):
        QWidget.__init__(self)
        B.__init__(self)

app = QApplication(sys.argv)
C() #works
D() #fails
-- example --

Ciao
Uwe



More information about the Python-list mailing list