Last active
April 2, 2020 10:15
-
-
Save olned/b54355d8ea7a4da483399172ea653540 to your computer and use it in GitHub Desktop.
External function call
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
# |
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
def f1(s1, s2): | |
print(s1, s2) |
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
import importlib | |
# Suppose it is loaded from a file | |
d = { | |
"module": "my_lib", | |
"function": "f1", | |
"args": ["Hello", "World!"] | |
} | |
module = importlib.import_module(d["module"]) | |
ext_func = getattr(module, d["function"]) | |
ext_func(*d["args"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment