If I wrap a function into a bigger function but I still want to have access to all the parameters of the inner function is customary to do:
def bigFun(par1, **kwargs):
innerFun(**kwargs)
Now, if I want to provide default values in the wrapper function and still have let the user to override these value I can do:
def bigFun(par1, **kwargs):
default_kwargs = dict(keyX=valueX, keyY=valueY, ...)
default_kwargs.update(**kwargs)
kwargs = default_kwargs
innerFun(**kwargs)
which I don't particularly like.
It seems a common enough situation to me.
Any other idiom do people use in this case?
def bigFun(par1, **kwargs):
kwargs[keyX] = kwargs.get(keyX, valueX)
innerFun(**kwargs)
or for multiple pairs:
def bigFun(par1, **kwargs):
for k,v in [('key1', 'val1'), ('key2', 'val2')]:
kwargs[k] = kwargs.get(k, v)
innerFun(**kwargs)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With