Python TypeError:\uuuu init\uuuuuu()接受4个位置参数,但给出了5个
我查过类似的问题,但大多数问题都与在Python TypeError:\uuuu init\uuuuuu()接受4个位置参数,但给出了5个,python,Python,我查过类似的问题,但大多数问题都与在\uuuu init\uuu定义中省略self参数有关 代码: 然而,在我将“optionsdic”添加到类之前,我的代码运行良好。添加后,我在标题中得到类型错误。我是否将**kwargs错误地用作参数 您需要使用**将选项DIC应用为关键字参数: testurl = steamurl("IDOTA2Match_570", "GetMatchHistory", "v001", **optionsdic) testurl = steamurl("IDOTA2M
\uuuu init\uuu
定义中省略self
参数有关
代码:
然而,在我将“optionsdic”添加到类之前,我的代码运行良好。添加后,我在标题中得到类型错误。我是否将
**kwargs
错误地用作参数 您需要使用**
将选项DIC
应用为关键字参数:
testurl = steamurl("IDOTA2Match_570", "GetMatchHistory", "v001", **optionsdic)
testurl = steamurl("IDOTA2Match_570", "GetMatchHistory", "v001", **optionsdic)
否则,它只是另一个传入dictionary对象的位置参数
这反映了函数签名中的语法。您应该使用
**
调用:
testurl = steamurl("IDOTA2Match_570", "GetMatchHistory", "v001", optionsdic)
这将把字典解压成单独的关键字参数。在
\uuuu init\uuuuu
中,由于**options
的原因,关键字参数将被打包到字典中。如果要将optionsdic
的内容作为单独的关键字参数传递,则需要使用**
:
testurl = steamurl("IDOTA2Match_570", "GetMatchHistory", "v001", **optionsdic)