Skip to content

Instantly share code, notes, and snippets.

@a-peyrard
Created October 10, 2019 00:24
Show Gist options
  • Save a-peyrard/23d13148591012b9e97b201ea9cd8928 to your computer and use it in GitHub Desktop.
Save a-peyrard/23d13148591012b9e97b201ea9cd8928 to your computer and use it in GitHub Desktop.
How to call a method dynamically from the current module
import sys
def foo_email(msg: str):
return "foo_email: " + msg
def foo_slack(msg: str):
return "foo_slack: " + msg
channel = "email"
result = getattr(sys.modules[__name__], "foo_" + channel)("Augustin")
print("result=" + result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment