我有两个类(ClassA
和ClassB
),并且ClassA
包含一个对象b
,它是ClassB
的一个实例。问题是我不能在Class A
中调用b
的方法。如何包含对象并在类中调用其方法?
class ClassB(object):
def __init__(self):
print('Class B init ...')
def show(self):
print('Showing class b')
class ClassA(object):
#__classb = ClassB()
def __init__(self, classb):
print('Class A init ...')
__classb = classb
def show(self):
__classb.show() # <=== I just want to do this!
b = ClassB()
a = ClassA(b)
a.show()
我希望得到的结果应该是:
Class B init ...
Class A init ...
Showing class b
但我遇到问题的this image显示:
我怎样才能解决呢?
感谢您的详细信息。有用! – Finnson