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

    def notifyObservers(self, event):
        for observer in self.observers:

    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:

print avoidTollObservable

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.

Need Your Help

How to wire up a progress indicator

wpf xaml .net-3.5 progress

I have a circular progress indicator. I'd like to add this progress bar to an application I'm working on but don't know how to wire it up correctly.

Is it possible in Flash to launch a JavaScript function (which uses AJAX) in a page that contains the Flash object itself?

javascript ajax flash

Here's our goal: in a website, show a nice menu "à la" iPhone in Flash and when we click on a menu, show a part of the site "under" the Flash menu.