Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python observer pattern

class Event(object):
    pass

class Observable(object):
    def __init__(self):
        self.callbacks = []
    def subscribe(self, callback):
        self.callbacks.append(callback)
    def fire(self, **attrs):
        e = Event()
        e.source = self
        for k, v in attrs.iteritems():
            setattr(e, k, v)
        for fn in self.callbacks:
            fn(e)
Comment

PREVIOUS NEXT
Code Example
Python :: whitelist the ip address django 
Python :: tensorflow create custom initializer 
Python :: python replace negative infinity 
Python :: python list pop 
Python :: add two dataframes together 
Python :: Uninstalling/removing a package is very easy with pip: 
Python :: id3 algorithm code in python 
Python :: mean pandas 
Python :: django not migrating 
Python :: SciPy Spatial Data 
Python :: eval in python 
Python :: Lucky four codechef solution 
Python :: python library 
Python :: python construct a string 
Python :: python pickle dataframe 
Python :: return array of sorted objects 
Python :: pandas multiply all dataframe 
Python :: get fields in object python 
Python :: is str in pzthon 
Python :: append to an array in 1st place python 
Python :: convert pandas data frame to latex file 
Python :: pop up window flutter 
Python :: keras model 2 outputs 
Python :: database with python connection 
Python :: python file get text by regular expression 
Python :: zip function python 
Python :: how to create dynamic list in python 
Python :: python dictionary input 
Python :: how to run python code in python 
Python :: reverse a list in python 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =