otherdict = some_called_function()`
# My values should take precedence over what's in the dict
otherdict.update(a=1, b=2)
# OR i am just supplying defaults in case they didn't
otherdict.setdefault('a', 1)
otherdict.setdefault('b', 2)
# In either case, then i just use kwargs only.
myfunc(**otherdict)
如果这是一个严重的问题,不要说出你的论点。只需使用splat参数:
并手动解析
args
。在2件事:
如果
myfunc(1,2, **otherdict)
是从其他地方调用的,而您无法控制otherdict
中的内容-您无能为力,则它们错误地调用了您的函数。调用函数需要确保没有冲突。如果你是调用函数。。。然后你只需要自己合并这些句子。i、 e.:
十
如果您的函数是从其他地方获取实际dict,则不需要使用
**
传递它。就像一个普通的论据一样传递口述:如果
^{pr2}$myfunc
被设计为接受任意数量的关键字参数,则只需要使用**kwargs
。像这样:如果你只是给它一个口述,那就不需要了。在
相关问题 更多 >
编程相关推荐