获取py文件函数名及动态调用
from aes_util import AesEncry import ast from efdir import fs import inspect def get_function_def_names(mod): fp = inspect.getabsfile(mod) code = fs.rfile(fp) t = ast.parse(code) g = ast.walk(t) arr = list(g) arr = list(filter(lambda r:type(r)==ast.FunctionDef,arr)) arr = list(map(lambda r:r.name,arr)) return(arr) get_function_def_names(AesEncry)
def run_model(self,name,*args, **kwargs): g = GraphDriver('***', '***', '***') name_list = get_function_def_names(GraphDriver) if name in name_list: eval(str(name))(*args, **kwargs)