我正在尝试从 Python 中的字符串 调用函数,如Calling a function of a module from a string with the function's name in Python 中所述。
不幸的是,这不起作用,Python 解释器会抛出一个错误:
TypeError: 'str' object is not callable
def current(self, t):
if self.iMode == None:
return self.i
else:
return getattr(self, 'iMode')(t)
错误是指最后一行。iMode
已设置为sinx(t)
,已在类中声明。
任何人都可以帮助我吗?