Skip to content

Instantly share code, notes, and snippets.

@olned
Last active April 2, 2020 10:15
Show Gist options
  • Save olned/b54355d8ea7a4da483399172ea653540 to your computer and use it in GitHub Desktop.
Save olned/b54355d8ea7a4da483399172ea653540 to your computer and use it in GitHub Desktop.
External function call
def f1(s1, s2):
print(s1, s2)
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