Created
January 14, 2019 09:33
-
-
Save ItsMeThom-zz/0d477538f80676b409083209465098a9 to your computer and use it in GitHub Desktop.
Signal pattern style function callbacks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # some arbitrary functions to call | |
| def func1(): | |
| print("called func1") | |
| def func2(): | |
| print("called func2") | |
| #register the methods with 'tags' tuples | |
| dee = { | |
| ('foo', 'bar', 'baz'): func1, | |
| ('foo', 'drum'): func2 | |
| } | |
| # call any func with the 'foo' tag | |
| key = 'foo' | |
| # call any function that contains the tag 'foo' | |
| for tag, func in dee.items(): | |
| if key in tag: | |
| dee[tag]() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment