Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 将两个变量传递给**kwargs_Python 3.x - Fatal编程技术网

Python 3.x 将两个变量传递给**kwargs

Python 3.x 将两个变量传递给**kwargs,python-3.x,Python 3.x,假设我有一个GUI窗口的输入表单,该表单要求一个新设置和该设置的值,然后它将该值传递给另一个对象,该对象管理设置并期望**KWARG作为输入: class SettingsForm(someFormClass): def onSubmit(self): new_setting = self.content['new setting'].get() new_value = self.content['value'].get() setting

假设我有一个GUI窗口的输入表单,该表单要求一个新设置和该设置的值,然后它将该值传递给另一个对象,该对象管理设置并期望**KWARG作为输入:

class SettingsForm(someFormClass):
    def onSubmit(self):
        new_setting = self.content['new setting'].get()
        new_value = self.content['value'].get()
        settings_instance.add_setting(new_setting=new_value)
这会将新的_值设置为文字字符串“new_setting”。我尝试过各种方法来解决这个问题,比如使用字典:

class SettingsForm(someFormClass):
    def onSubmit(self):
        new_setting = self.content['new setting'].get()
        new_value = self.content['value'].get()
        mydict = {}
        mydict[new_setting] = new_value
        settings_instance.add_setting(**mydict)

这是可行的,但对于一对值来说没有多大意义。。。是否有一种明显的方法我没有注意到?

使用
…add\u setting(**{mydict:new\u value})
可能会使它更可读,但这是我所能想到的所有方法,实际上效果很好。