Suppose I have some function, f
:
def f (a=None):
print a
Now, if I have a dictionary such as dct = {"a":"Foo"}
, I may call f(**dct)
and get the result Foo
printed.
However, suppose I have a dictionary dct2 = {"a":"Foo", "b":"Bar"}
. If I call f(**dct2)
I get a
TypeError: f() got an unexpected keyword argument 'b'
Fair enough. However, is there anyway to, in the definition of f
or in the calling of it, tell Python to just ignore any keys that are not parameter names? Preferable a method that allows defaults to be specified.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…