Python: TypeError: XXX() takes exactly 1 argument (2 given)

来源:互联网 发布:网络水军如何找站 编辑:程序博客网 时间:2024/06/05 19:57

在调用某一个类A的方法时,出现以下错误:TypeError: XXX() takes exactly 1 argument (2 given)


Python在调用一个实例的方法是,将instance本身也作为一个参数传入,即

调用方法:insA.method_1(k)

其实调用的是:ins_A.method_1(self, k)


因此在类A中定义方法method_1时,必须包含self参数:

method_1(self, input)

0 0
原创粉丝点击