且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在python中的另一个方法中调用类方法?

更新时间:2023-11-22 14:16:28

我会尝试这样的操作,因为这意味着您不必更改类One.这减少了您必须更改的类的数量,从而隔离了更改和错误的范围;并保持One类的行为

I'd try something like this as it means you don't have to change class One. This reduces the amount of classes you have to change, which isolates the change and the scope for error; and maintains the behaviour of class One

class One:
     def a(self):
         print('thanks')

class Two:
     def b(self, test):
         test = One()
         print('okay', end=' ')
         test.a()