importlib と getattr() を使えば実現できます。
importlib --- import の実装 — Python 3.8.5 ドキュメント
python
1import importlib
2
3module_name = "a"
4func_name = "func_a"
5
6module = importlib.import_module(module_name)
7func = getattr(module, func_name)
8
9func() # a.func_a
a.py
python
1def func_a():
2 print("a.func_a")
b.py
python
1def func_b():
2 print("b.func_b")
追記
python
1import importlib.util
2from pathlib import Path
3
4module_path = "/data/notebook/test/a.py"
5class_name = "MyClass"
6func_name = "func"
7
8module_path = Path(module_path)
9spec = importlib.util.spec_from_file_location(module_path.stem, module_path)
10module = importlib.util.module_from_spec(spec)
11spec.loader.exec_module(module)
12
13MyClass = getattr(module, class_name)
14
15inst = MyClass()
16func = getattr(inst, func_name)
17
18func() # func called
/data/notebook/test/a.py
python
1class MyClass:
2 def func(self):
3 print("func called")