游雁
2023-12-13 7012ca2efc130103c4acd24e3678c7ae280f8db4
1
2
3
4
5
6
7
8
9
10
11
12
13
import importlib
 
 
def dynamic_import(import_path):
    """dynamic import module and class
 
    :param str import_path: syntax 'module_name:class_name'
    :return: imported class
    """
 
    module_name, objname = import_path.split(":")
    m = importlib.import_module(module_name)
    return getattr(m, objname)