是否可以在 python 中“打包”参数?我在库中有以下功能,我无法更改(简化):
def g(a,b=2):
print a,b
def f(arg):
g(arg)
我可以
o={'a':10,'b':20}
g(**o)
10 20
但我可以/我如何通过这个f
?
这就是我不想要的:
f(**o)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: f() got an unexpected keyword argument 'a'
f(o)
{'a': 10, 'b': 20} 2