Python的参数作为一个字典 [英] Python arguments as a dictionary
本文介绍了Python的参数作为一个字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何,我可以得到参数名称和传递给作为字典的方法?
How can I get argument names and their values passed to a method as a dictionary?
我要为GET请求作为以打造URL的HTTP API的一部分指定可选和必需的参数。我不知道的,使这个Python化的最佳途径。
I want to specify the optional and required parameters for a GET request as part of a HTTP API in order to build the URL. I'm not sure of the best way to make this pythonic.
推荐答案
使用与 pfixed一个参数$ P $ **
。
>>> def foo(**args):
... print(args)
...
>>> foo(a=1, b=2)
{'a': 1, 'b': 2}
这篇关于Python的参数作为一个字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文