[Tutor] quirky multiple inheritance example!?

Alan Gauld alan.gauld at freenet.co.uk
Thu Feb 9 00:59:35 CET 2006


 # This *FAILS* with AttributeError: 'FancyPublisher'
# object has no attribute 'listeners'
class FancyPublisher(threading.Thread, Publisher):
   def __init__(self):
      super(FancyPublisher, self).__init__()

F = FancyPublisher()
F.register('me', None)
-------------------

The problem is that super appears to only work with single inheritance.
There may be a way to makle it work for multiple inheritance by changing 
the second parameter but the documentration is a bit thin!!

For that reason I tend not to use super but instead prefer the classical 
method of explicit call:

class FancyPublisher(threading.Thread, Publisher):
   def __init__(self):
        Publisher.__init__(self)

That way its clear which superclass is being called and I can call
all of the superclasses in whichever order I want.

Hopefully someone can explain how to use super properly to 
do this, but it beats me! (This is why super() doesn't appear in 
the OOP topic in my tutor, I found it more confusing than 
helpful for a beginner - and even for me!)

Alan G


More information about the Tutor mailing list