multiple inheritance & __init__
Robb Shecter
rs at onsitetech.com
Wed Jul 3 13:58:14 EDT 2002
Interesting - I had the sazme issue yesterday. I forgot / didn't
realize, though, that you have to call __init__ explicitly. I also
implemented an Observer class that I used via multiple inheritance. So,
although I'm not answering your question, I thought I'd post the classes
that I came up with. They're fairly Java-like - I have mixed feelings
about that:
class Observable:
"""
An object that generates events that other objects are
interested in knowing about.
"""
def __init__(self):
self.__observerList = []
def addObserver(self, anObserver):
"Add the given listener to the list of observers"
self.__observerList.append(anObserver)
def notifyObservers(self, aMessage):
"""Call the notify() method on all observers in my list.
The aMessage parameter is appliction-specific."""
for observer in self.__observerList:
observer.notify(self, aMessage)
class Observer:
"""
An object that wishes to be notified when something
has happened.
"""
def notify(self, aSender, aMessage):
"Recieve a message from an observable object."
print `self` + " received notification: " + `aMessage`
More information about the Python-list
mailing list