class human(object):
def __init__(self, name=''):
self.name = name
@property
def name(self):
return self._name
@name.setter
def name(self, value):
self._name = value
class superhuman(human):
@property
def name(self):
return 'super ' + name
s = superhuman('john')
print s.name
# Doesn't work :("AttributeError: can't set attribute"
s.name = 'jack'
print s.name
Tôi muốn có thể ghi đè thuộc tính nhưng có thể sử dụng trình thiết lập của cha mẹ siêu mà không cần phải ghi đè bộ cài đặt trong lớp con.Giá trị ghi đè của Python không cần thiết lập
Đó có phải là pythonicaly có thể không?