内の文字列名から関数を呼び出す:私は、私はそれがしたいname
の値をチェックする必要はありません私は、次の2つのクラス持つオブジェクト
x= B()
x.caller("call") # I want to have caller() invoke call() on the name.
:
class A(object):
def caller(self,name):
# want to invoke call() here when name="call"
class B(A):
def call(self):
print("hello")
は以下を考慮し自動的に与えられた文字列を自己の関数として呼び出す。
ああありがとうKenji;) – MarMan29
どうして 'getattr(self、name)()'? –