Python key word arguments

Posted by pythonic metaphor on Stack Overflow See other posts from Stack Overflow or by pythonic metaphor
Published on 2010-04-30T15:34:24Z Indexed on 2010/04/30 15:37 UTC
Read the original article Hit count: 345

Filed under:
|

I have several layers of function calls, passing around a common dictionary of key word arguments:

def func1(**qwargs):
    func2(**qwargs)
    func3(**qwargs)

I would like to supply some default arguments in some of the subsequent function calls, something like this:

def func1(**qwargs):
    func2(arg = qwargs.get("arg", default), **qwargs)
    func3(**qwargs)

The problem with this approach is that if arg is inside qwargs, a TypeError is raised with "got multiple values for keyword argument".

I don't want to set qwargs["arg"] to default, because then func3 gets this argument without warrant. I could make a copy.copy of the qwargs and set "arg" in the copy, but qwargs could have large data structures in it and I don't want to copy them (maybe copy.copy wouldn't, only copy.deepcopy?).

What's the pythonic thing to do here?

© Stack Overflow or respective owner

Related posts about python

Related posts about keyword-argument