[Python]通过函数名字符串调用函数
2014-05-29 14:52
281 查看
可用方法整理如下:
1、
2、
3、
参考资料:
[1]:http://stackoverflow.com/questions/3061/calling-a-function-from-a-string-with-the-functions-name-in-python
1、
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()
3、
locals()["fun_name_string"]() globals()["fun_name_string"]()
参考资料:
[1]:http://stackoverflow.com/questions/3061/calling-a-function-from-a-string-with-the-functions-name-in-python
相关文章推荐
- Python如何获取到当前函数名和通过字符串调用函数
- [Python]通过函数名字符串调用函数
- 199 c 通过函数名字符串调用函数
- C++ 中通过函数名字的字符串调用函数
- 通过函数名字符串调用函数【C语言版】
- 通过同名字符串来调用函数<python>
- js中通过函数名字符串调用函数
- 通过Python的内置字符串处理函数来处理字符串的方法和整理
- 通过函数名字符串调用函数【C语言版】
- js中通过函数名字符串调用函数
- C++ 中通过函数名字的字符串调用函数
- 函数调用通过函数名字符串调用函数【C语言版】
- 自已写的js函数,用来通过传入年月(字符串,如‘201007’)得到前一个月的年月
- python 字符串处理函数
- 字符串转换成python中exec能执行的函数
- Dive Into Python 学习记录1-函数/模块导入/字典/列表/元组/字符串分割、连接、格式化/映射list/
- Python修炼--常用字符串、数学函数
- PYTHON字符串常用函数
- JavaScript 通过字符串参数(函数名),调用对应的函数
- js字符串当函数名调用函数