PythonのPHPのcall_user_func_arrayに相当するものはありますか?あなたの関数名が文字列であれば、あなたができるPythonのPHP call_user_func_array
function(*array)
PythonのPHPのcall_user_func_arrayに相当するものはありますか?あなたの関数名が文字列であれば、あなたができるPythonのPHP call_user_func_array
function(*array)
:
は*が先行配列を持つ関数を呼び出し
getattr(obj, 'func')(*arr) # where obj is the namespace that hold func
これは正しい答えです。 – cwallenpoole
あなたの関数を呼び出すと*
記号で引数を渡すことができます
ex。
def add(a, b):
return a + b
arg = (1, 2)
add(*arg)
また、二重星**
元で引数のペアを渡すために辞書を使用することができます。
arg = {a: 1, b: 2}
add(**arg)
これはまさに私が言いたいことです。 – DerKlops