python properties and inheritance

后端 未结 10 1461
粉色の甜心
粉色の甜心 2020-12-12 18:06

I have a base class with a property which (the get method) I want to overwrite in the subclass. My first thought was something like:

class Foo(object):
    d         


        
10条回答
  •  粉色の甜心
    2020-12-12 18:47

    class Foo:
        # Template method
        @property
        def age(self):
            return self.dothis()
        # Hook method of TM is accessor method of property at here
        def dothis(self):
            return 11
    class Bar(Foo):
        def dothis(self):
            return 44
    

    Same as Nizam Mohamed, just to mention that style guide 2.13.4 using both template method and property

提交回复
热议问题