How to invoke an function on an object dynamically by name?
This question already has an answer here:
使用“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/55162.html
下一篇: 如何根据名称动态调用对象的函数?