“ B”对象没有属性“ _B__string”

时间:2018-12-01 22:15:23

标签: python python-2.7 object inheritance

因此,我有B类及其上级A

class A(object):
    def __init__(self, string):
        self.__string = string.lower()

class B(A):
    def __init__(self, string):
        super(B, self).__init__(string)

    def __getitem__(self, index):
        return self.__string[index]

当我实例化B并尝试获取项目时:

steve = B("foo")
print steve[0]

我收到属性错误:

'B' object has no attribute '_B__string'

问题出在哪里,我该如何解决

0 个答案:

没有答案