Problems passing a user-defined between modules parameter
I am getting some odd behaviour passing an instance of Observable around. It seems to degenerate into a list and I cannot work out why.
class Observable(): def __init__ (self): self.observers =  def addObserver(self, observer): self.observers.append(observer) def notifyObservers(self, event): for observer in self.observers: observer.observeEvent(event) def __str__(self): print self.observers
from patterns import Observable def loadData (): ''' helper function ''' print "l1" avoidTollObservable = Observable () dataLocation = os.path.join(os.path.dirname(__file__), 'DATA', "links.dat").replace('\\','/') print "reading edges" edgesDict = routing._readNetworkDataFile (dataLocation, avoidTollObservable)
from patterns import Observable def _readNetworkDataFile ( absFilePath , avoidTollObservable): print "debug:" print avoidTollObservable print "debug end"
The program produces:
> > debug: >  > [01/May/2013 08:40:49] "GET /route/-110884.64901689/6782501.6151699/-250884.64901689/7299908.890599588/?_=1367415648664 HTTP/1.1" 500 11571
The last line is in mauve (indicating that there is an error,I think)
When doing this:
What you are basically doing is calling the Observable objects __str__() method
def __str__(self): print self.observers # In your code this is declared as a list
The self.observers is an empty list (its how its initialised) so your output is going to be , if you were to add a value add an item to self.observers before passing it to routing._readNetworkDataFile then the value of print avoidTollObservable would not be an empty list.
If you were to change __str__() to:
def __str__(self): print 'Object ID' + self
Then the output would be the id of the object and not the value of the self.observers attribute.