将一个函数的所有参数传递给另一个函数 [英] Passing all arguments of a function to another function
问题描述
我想将传递给函数(func1
)的所有参数作为参数传递给func1
内的另一个函数(func2
)这可以通过在被调用的 func1
中使用 *args, *kwargs
并将它们传递给 func2
来完成,但还有其他方法吗?>
原来
def func1(*args, **kwargs):func2(*args, **kwargs)
但是如果我的 func1 签名是
def func1(a=1, b=2, c=3):
如何在不使用的情况下将它们全部发送到 func2
def func1(a=1, b=2, c=3):func2(a, b, c)
有没有 javascript callee.arguments
中的方法?
显式优于隐式 但如果你真的不想输入几个字符:
def func1(a=1, b=2, c=3):func2(**locals())
locals()
都是局部变量,所以你不能在调用 func2
之前设置任何额外的变量,否则它们也会被传递.
I want to pass all the arguments passed to a function(func1
) as arguments to another function(func2
) inside func1
This can be done with *args, *kwargs
in the called func1
and passing them down to func2
, but is there another way?
Originally
def func1(*args, **kwargs):
func2(*args, **kwargs)
but if my func1 signature is
def func1(a=1, b=2, c=3):
how do I send them all to func2, without using
def func1(a=1, b=2, c=3):
func2(a, b, c)
Is there a way as in javascript callee.arguments
?
Explicit is better than implicit but if you really don't want to type a few characters:
def func1(a=1, b=2, c=3):
func2(**locals())
locals()
are all local variables, so you can't set any extra vars before calling func2
or they will get passed too.
这篇关于将一个函数的所有参数传递给另一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!