【Python】fun_connect_main() missing 1 required positional argument: 'self'

fun_connect_main() missing 1 required positional argument: 'self'

调用类的方法时,注意不同的状态。

 

调用类的实例方法,

      1、无参数时,如果没有直接实例该类,必须加:self;

            或者在调用方法时,提前定义这个类的实例,才能直接调用该类的实例方法。

      2、有参数时,也要加self,必须加后面的参数。

调用类的静态方法,不用加self,跟据参数匹配进行调用。

调用类的类方法时,根据参数匹配即可。

 

Passing mainController.MainLogic instead of SerialControl.MySerialControl. Is this intentional? less... (Ctrl+F1) 
Inspection info: This inspection checks for calls of a method by class while passing an instance of a different class as self parameter:
  foo = Foo()
  Bar.baz(foo, *more)
Sometimes this may be intentional and correct. But when unintentional, this leads to subtle bugs.

有时这可能是有意和正确的。但是,当无意识的时候,这会导致细微的bug。

总结:

规范用法:调用类的实例方法一般要先实例化该类。

快速用法:直接加self,即在self对应的类实例化了。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值