Skip to content

Instantly share code, notes, and snippets.

@ItsMeThom-zz
Created January 14, 2019 09:33
Show Gist options
  • Select an option

  • Save ItsMeThom-zz/0d477538f80676b409083209465098a9 to your computer and use it in GitHub Desktop.

Select an option

Save ItsMeThom-zz/0d477538f80676b409083209465098a9 to your computer and use it in GitHub Desktop.
Signal pattern style function callbacks
# 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