📜  从字符串中获取 python 类 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:14.376000             🧑  作者: Mango

代码示例1
import importlib

def class_for_name(module_name, class_name):
    # load the module, will raise ImportError if module cannot be loaded
    m = importlib.import_module(module_name)
    # get the class, will raise AttributeError if class cannot be found
    c = getattr(m, class_name)
    return c