Вот пример:
Код: Выделить всё
class A(object):
def __init__(self, color):
self._color = color
@property
def color(self):
return self._color
class B(A):
def __init__(self, color, height, width):
super().__init__(color)
self._height = height
self._width = width
@property
def height(self):
return self._height
@property
def width(self):
return self._width
Код: Выделить всё
b_inst = B('red', 10, 20)
val = [{p: b_inst.__getattribute__(p)} for p in dir(B)
if isinstance(getattr(B, p), property)]
print(val)
>> [{'color': 'red'}, {'height': 10}, {'width': 20}]
Теперь я просто хочу получить значения свойств, определенных ТОЛЬКО в классе B, то есть высоту и ширину.
п>
Подробнее здесь: https://stackoverflow.com/questions/459 ... g-to-speci