For example:
class Example:
def __init__(self):
self.v = 0
@property
def value(self):
return self.v
@value.setter
def value(self, v):
self.v = v
class SubExample(Example):
pass
Would it be possible to rewrite just the getter to value in SubExample?
You can do so like this
However, this only works if
Exampleis a new-style class (class Example(object):) rather than an old style class (class Example:), as it is in your example code.Warning: Thomas pointed out in the comments that this method may not behave as expected if you’re using multiple inheritance (
class Foo(Bar, Baz)).