我已閱讀所有關於此主題的類似帖子,但沒有發現與我的問題有關的方式,這有助於我弄清楚發生了什麼。'super'對象沒有屬性'_Parent__method'
class A:
def __init__(self, value):
self.__value = value
self.__conn = httpsconnection # Specifics don't matter
class B(A):
def __init__(self, id, type, value):
super().__init__(value)
self.data = self.__create_sub_class(id, type)
def __create_sub_class(self, id, type):
self.__conn.request(...)
...
return data
class C(B):
def __init__(self, id, value):
super().__init__(id, externalVariable, value)
我得到的錯誤是AttributeError: 'C' object has no attribute '_B__conn'
不該類C
繼承B
它繼承了它從A
變量?
爲什麼使用雙下劃線名稱?這些都是明確設計的,以避免可繼承性。 –
https://docs.python.org/3/tutorial/classes.html#private-variables – NPE
@MartijnPieters它們是我的私有變量。我在學習編程時習慣用另一種語言。 – Spedwards