TypeError: got multiple values for argument

前端 未结 7 2353
忘掉有多难
忘掉有多难 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 06:23

    My issue was similar to Q---ten's, but in my case it was that I had forgotten to provide the self argument to a class function:

    class A:
        def fn(a, b, c=True):
            pass
    

    Should become

    class A:
        def fn(self, a, b, c=True):
            pass
    

    This faulty implementation is hard to see when calling the class method as:

    a_obj = A()
    a.fn(a_val, b_val, c=False)
    

    Which will yield a TypeError: got multiple values for argument. Hopefully, the rest of the answers here are clear enough for anyone to be able to quickly understand and fix the error. If not, hope this answer helps you!

提交回复
热议问题