通过类名调用类
下面的程序可以通过输入字符串(类名)调用类
from .a import A
from .b import B
from .c import C
def get_cls(name):
sn = sys.modules[__name__]
c = [i for i in dir(sn) if callable(getattr(sn, i))]
temp_list = [current_usr.lower() for current_usr in c]
if name.lower() in temp_list:
p = temp_list.index(name.lower())
return getattr(sn, (c[p]))
else:
raise ValueError(name + "类不存在")