TypeError: got multiple values for argument

前端 未结 7 2333
忘掉有多难
忘掉有多难 2020-11-28 06:13

I read the other threads that had to do with this error and it seems that my problem has an interesting distinct difference than all the posts I read so far, namely, all the

7条回答
  •  借酒劲吻你
    2020-11-28 06:24

    Simply put you can't do the following:

    class C(object):
        def x(self, y, **kwargs):
            # Which y to use, kwargs or declaration? 
            pass
    
    c = C()
    y = "Arbitrary value"
    kwargs["y"] = "Arbitrary value"
    c.x(y, **kwargs) # FAILS
    

    Because you pass the variable 'y' into the function twice: once as kwargs and once as function declaration.

提交回复
热议问题