【发布时间】:2016-04-20 19:45:24
【问题描述】:
我想通过另一个新实例调用一个实例中的方法,如下所示:
class parentClass:
# Some methods here
class a:
def __init__(self, otherclass):
otherclass.__foo(a);
class b:
def __foo(self, firstclass):
#do something with firstclass
pClass = parentClass();
classB = pClass.b();
classA = pClass.a(classB);
但是使用这段代码我会得到这种错误:
AttributeError: b instance has no attribute '_a__foo'
我已经尝试在方法 __foo() 之前添加它:
@classmethod
但这仍然不起作用。
感谢您的帮助!
【问题讨论】:
标签: python class methods instance