TypeError: method() takes 1 positional argument but 2 were given

前端 未结 9 1002
孤街浪徒
孤街浪徒 2020-11-22 05:02

If I have a class...

class MyClass:

    def method(arg):
        print(arg)

...which I use to create an object...

my_objec         


        
9条回答
  •  遥遥无期
    2020-11-22 05:27

    In my case, I forgot to add the ()

    I was calling the method like this

    obj = className.myMethod
    

    But it should be is like this

    obj = className.myMethod()
    

提交回复
热议问题