可用方法整理如下:
1、
- import module_name
- methodToCall = getattr(module_name, 'fun_name_string')
- result = methodToCall()
import module_name
methodToCall = getattr(module_name, 'fun_name_string')
result = methodToCall()
2、
- module_instance = importlib.import_module('module_name_string')
- methodToCall = getattr(module_instance,'fun_name_string')
- result = methodToCall()
module_instance = importlib.import_module('module_name_string')
methodToCall = getattr(module_instance,'fun_name_string')
result = methodToCall()
3、
- locals()["fun_name_string"]()
- globals()["fun_name_string"]()
locals()["fun_name_string"]()
globals()["fun_name_string"]()