Python:XXX missing X required positional argument: 'self'

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python:XXX missing X required positional argument: 'self'相关的知识,希望对你有一定的参考价值。

代码的一个小小Bug有时候会让人焦头烂额,费了很大劲搞明白的问题,如果不记录下来,是很容易遗忘的!

 

定义一个类,如果按照以下的方式使用,则会出现TypeError: testFunc() missing 1 required positional argument: ‘self‘。如果认真细究的话,笔者曾反复修改参数,但是于事无补。

技术分享

 

在Python中,应该先对类进行实例化,然后在应用类,如下图所示。注意,实例化的过程是应该待括号的。

技术分享

 

总结:Python中,类应该先实例化,然后再使用类!

 

以上是关于Python:XXX missing X required positional argument: 'self'的主要内容,如果未能解决你的问题,请参考以下文章

gdb调试时的问题Missing separate debuginfos, use: debuginfo-install glibc-XXX

解决python 提示 SyntaxError: Missing parentheses in call to 'print'

maven使用私服以后,Missing artifact xxx:xxx:jar:xx的问题

推送到数组会话 - Laravel 8.x

python系列SyntaxError:Missing parentheses in call to 'print'

cmake ninja: error: 'xxx', needed by 'xxx', missing and no known rule to make it