From cc7aeeac3162fd6a51a277d5dd91a55cf7a25bb1 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Wed, 29 Jan 2025 16:54:10 +0100 Subject: [PATCH] misc: Add load_function() Signed-off-by: Jan Lindemann --- tools/python/jwutils/misc.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/python/jwutils/misc.py b/tools/python/jwutils/misc.py index 60c109e..ca11e4a 100644 --- a/tools/python/jwutils/misc.py +++ b/tools/python/jwutils/misc.py @@ -105,6 +105,10 @@ def load_class_names(path, baseclass, flt=None, remove_flt=False): # export def load_object(module_path, baseclass, class_name_filter=None, *args, **kwargs): # export return load_class(module_path, baseclass, class_name_filter=class_name_filter)(*args, **kwargs) +def load_function(module_path, name): # export + mod = importlib.import_module(module_path) + return getattr(mod, name) + def commit_tmpfile(tmp: str, path: str) -> None: # export caller = log.get_caller_pos() if os.path.isfile(path) and filecmp.cmp(tmp, path):