我在传递 Observable 实例时遇到了一些奇怪的行为。它似乎退化成一个列表,我不知道为什么。
模式.py
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
视图.py
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)
路由.py
from patterns import Observable
def _readNetworkDataFile ( absFilePath , avoidTollObservable):
print "debug:"
print avoidTollObservable
print "debug end"
该程序产生:
>
> debug:
> []
> [01/May/2013 08:40:49] "GET /route/-110884.64901689/6782501.6151699/-250884.64901689/7299908.890599588/?_=1367415648664 HTTP/1.1" 500 11571
最后一行是淡紫色的(表示有错误,我认为)