A very simple implementation of the observer pattern
Project description
A simple implementation of the observer pattern.
import observer
# Create a subject and list the events it might fire
foo = observer.Subject('bar', 'baz')
# Add a listener
def foo_bar_listener(*args):
print("heard 'bar'", args)
foo('bar', foo_bar_listener)
# fire events
foo.fire('bar', 1, 2, 3)
# -> heard 'bar' (1, 2, 3)
# Trying to listen to an unregistered event throws an error
foo('snorble', lambda: None)
# -> AssertionError: snorble is not a valid event for this subject
# Same with trying to fire an unregistered event
foo.fire('snorble')
# -> AssertionError: snorble is not a valid event for this subject
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
observer.simple-1.0.0.tar.gz
(1.9 kB
view details)
File details
Details for the file observer.simple-1.0.0.tar.gz.
File metadata
- Download URL: observer.simple-1.0.0.tar.gz
- Upload date:
- Size: 1.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f61cb8840051bf507707cb68cd4869d38c8cd6dfa890f9c13dbbae65006c4c5
|
|
| MD5 |
560b6e1e999d9c84a01135eba072769c
|
|
| BLAKE2b-256 |
de21212a6f5866aa49d8c4ff98708e714dee3f1fcc6dbed0ed617ce3f1fb3963
|