【发布时间】:2021-12-14 16:53:27
【问题描述】:
我有 2 个如下数据类:
from dataclasses import dataclass
@dataclass
class Line:
x: int
length: int
color: str
@dataclass
class Rectangle(Line):
y: int
height: int
fill: bool
def get_dict(self):
""" return only y, height, and fill """
如果我构造一个Rectangle对象,是否可以识别出哪些属性是从父数据类继承的?
例如,如何在Rectangle 中实现get_dict() 方法而不显式输入所有变量及其值?
【问题讨论】:
标签: python-3.x inheritance python-dataclasses