传递函数的所有参数给另一个函数 [英] Passing all arguments of a function to another function

查看:199
本文介绍了传递函数的所有参数给另一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过传递给函数的所有参数( FUNC1 )作为参数传递给另一个函数( FUNC2 )在 FUNC1
这是可以做到的 * ARGS,* kwargs 在名为 FUNC1 ,并通过他们到 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?

最初

def func1(*args, **kwargs):
    func2(*args, **kwargs)

但如果我的func1的签名

but if my func1 signature is

def func1(a=1, b=2, c=3):

我怎么他们都送到FUNC2,而无需使用

how do I send them all to func2, without using

def func1(a=1, b=2, c=3):
    func2(a, b, c)

有没有办法在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())

当地人()都是局部变量,所以你不能调用之前设置任何额外的增值经销商 FUNC2 或他们将获得通过了。

locals() are all local variables, so you can't set any extra vars before calling func2 or they will get passed too.

这篇关于传递函数的所有参数给另一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆