如何根据名称动态调用对象的函数?
这个问题在这里已经有了答案:
使用“getattr”:http://docs.python.org/library/functions.html?highlight=getattr#getattr
obj = MyClass()
try:
func = getattr(obj, "dostuff")
func()
except AttributeError:
print "dostuff not found"
链接地址: http://www.djcxy.com/p/55161.html
上一篇: How to invoke an function on an object dynamically by name?