Passing all arguments of a function to another function

后端 未结 3 981
迷失自我
迷失自我 2020-12-02 21:47

I want to pass all the arguments passed to a function(func1) as arguments to another function(func2) inside func1 This can be done wit

3条回答
  •  清歌不尽
    2020-12-02 22:30

    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.

提交回复
热议问题