Created
October 10, 2019 00:24
-
-
Save a-peyrard/23d13148591012b9e97b201ea9cd8928 to your computer and use it in GitHub Desktop.
How to call a method dynamically from the current module
This file contains 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
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