簡體   English   中英

如何訪問另一個基礎 class 的基礎 class 的屬性?

[英]How can I access a property of the base class of another base class?

假設,我有以下情況:

class TopBaseClass:
    ... ...
    ... ...
    @property
    def top_property(self):
        return self.__top_property
    
    @top_property.setter
    def top_property(self, top_property):
        self.__top_property = top_property

class IntermediateBaseClass(TopBaseClass):
    ...

class LowestClass(IntermediateBaseClass):
    ... ...
    ... ...
    def lowest_function(self):
        something = ""

        ... ...
         
        return something

現在,我想從lowest_function()訪問top_property

我怎樣才能做到這一點?

我嘗試了以下但沒有工作:

something = str(super().super().top_property)

它給了我一個錯誤。

那么,該怎么做呢?

你想做:

something = self.top_property

該屬性是您的實例的一部分,可以直接引用。 getter 將用於檢索值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM