开发者

PHPs call_user_func_array in Python

Is there an equivalent in Python for PH开发者_StackOverflow社区P's call_user_func_array?


Call the function with the array preceded by *:

function(*array)


if your function name is a string, you could do:

getattr(obj, 'func')(*arr)     # where obj is the namespace that hold func


Your can call function and pass arguments by * sign
ex.

def add(a, b):
    return a + b

arg = (1, 2)
add(*arg)

You also can use dict to pass argument pairs by double star **

ex.

arg = {a: 1, b: 2}
add(**arg)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜