Forwarding kwargs in python

Viewed 295

I wish to forward the kwargs of a function to another function, but add a further argument. The following does not work however...

def A(**kwargs):
    B(type="moose", kwargs=kwargs)

def B(**kwargs):
    print(kwargs) # I'd like to see {"call": True, "seven": 8, "type": "moose" }

A(call=True, seven=8)
1 Answers

Just call B() with **kwargs:

def A(**kwargs):
    B(type="moose", **kwargs)

def B(**kwargs):
    print(kwargs) 

A(call=True, seven=8)

Prints:

{'type': 'moose', 'call': True, 'seven': 8}
Related