我有功能定义:
def setup(self, **kwargs):
pass
并称之为:
params = {
"advert_id": adv_id,
"enabled": True,
"from_hour": 2,
"to_hour": 1,
"interval": 0,
"weekdays": [1]
}
setup(params)
我试图将params
作为对象传递,但它不起作用。我知道正确的方法是:
setup(advert_id=1,enabled=True,from_hour=3,to_hour=4,interval=0,weekdays=[])
无论如何,我不想枚举所有参数,并希望将其打包到对象。
答案 0 :(得分:3)
在函数调用中解包params
:
def setup(self, **kwargs):
pass
params = {
"advert_id": adv_id,
"enabled": True,
"from_hour": 2,
"to_hour": 1,
"interval": 0,
"weekdays": [1]
}
setup(**params)