I'm not sure that it's possible, I would like to unpack dictionary into function but I haven't similar parameters. Is it possible to easily restrict a dictionary to a subset?
def foo(a=0, b=0, c=0):
print("a=%s, b=%s, c=%s"%(a,b,c))
my_dict = {'a':10, 'b':20, 'd':40}
foo(**my_dict)
Output
TypeError Traceback (most recent call last)
<ipython-input-1-d40731664736> in <module>()
3
4 my_dict = {'a':10, 'b':20, 'd':40}
----> 5 foo(**my_dict)
TypeError: foo() got an unexpected keyword argument 'd'
And I want to obtain
a=10, b=20, c=0
result where 'd' is automatically rejected.
It's just an example. In my case the function is not mine, I cannot redefined her parameters, foo is unmodifiable.
I have many functions in similar case as foo() and these functions are object's methods.
Any ideas?