[Tutor] quirky multiple inheritance example!?

Marcus Goldfish magoldfish at gmail.com
Wed Feb 8 23:07:38 CET 2006


Hi,

I ran across a strange problem using mulitple inheritance that I hope
someone can explain.  Basically, I am implementing a Publisher pattern, and
when I try to add threading, the order I list Base classes matters!  Here is
the short sample code-- all help explaining this is appreciated!

Thanks,
Marcus

---
import threading

class Publisher(object):
   def __init__(self): self.listeners = {}
   def register(self, id, object):
      self.listeners[id] = self.listeners.get(id, object)


 # 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)


# However, this succeeds!?
 class FancyPublisher(Publisher, threading.Thread):
   def __init__(self):
      super(FancyPublisher, self).__init__()

F = FancyPublisher()
F.register('me', None)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060208/ebc298bb/attachment-0001.html 


More information about the Tutor mailing list