我知道在* arg,** kwarg上有很多问题/答案。不过,我做得有点倒退,但没有找到它解决(也许我只是不知道该怎么问这样的问题。)无论如何,我希望能够简化以下:将函数参数作为字典使用
def foo(self, arg1, arg2, arg3):
my_dict = dict(arg1=arg1, arg2=arg2, arg3=arg2)
my_str = "{arg1} went up the {arg2} hill to fetch a pail of {arg3}".
format(**my_dict)
注,我不会将foo定义为(self,** kwargs),因为我喜欢填充函数的自动完成组件。
感谢,
所以你想从一些参数创建一个字典? – nbro 2015-02-06 17:13:23
可能会使用'** locals()'? – mshsayem 2015-02-06 17:19:07
@mshsayem - 如何写作答案? – tdelaney 2015-02-06 17:31:55