如何通过从与被调用方法相同的类中的另一个方法提供名称来执行方法?像这样:python变量方法名称
class Class1:
def __init__(self):
pass
def func1(self, arg1):
# some code
def func2(self):
function = getattr(sys.modules[__name__], "func1") # apparently this does not work
任何建议?
如果你知道你想要的方法,就没有理由使用'getattr' - 只需抓住它。 –