How to get all named args in a dict?

Chris Rebert clp2 at rebertia.com
Wed May 13 23:59:39 CEST 2009


On Wed, May 13, 2009 at 2:50 PM, kj <socyl at 987jk.com.invalid> wrote:
>
>
> Suppose I have the following:
>
> def foo(x=None, y=None, z=None):
>    d = {"x": x, "y": y, "z": z}
>    return bar(d)
>
> I.e. foo takes a whole bunch of named arguments and ends up calling
> a function bar that takes a single dictionary as argument, and this
> dictionary has the same keys as in foo's signature, so to speak.
>
> Is there some builtin variable that would be the same as the variable
> d, and would thus obviate the need to explicitly bind d?

def foo(**kwargs):
    return bar(kwargs)

I would suggest you read the Python tutorial.

Cheers,
Chris
-- 
http://blog.rebertia.com



More information about the Python-list mailing list