【发布时间】:2020-09-05 05:38:09
【问题描述】:
我有一个用 openpyxl Cell 对象初始化的 python 类。它是一个传统的单元类,它接受 Cell 对象并读取 Cell 对象的一些属性并将其存储为自己的,
import openpyxl as oxl
class oxl_cell_objectclass(object):
def __init__(self, cell):
self.cell = cell
self.xl_column = cell.column
self.xl_row = cell.row
self.cell_value = cell.value
如何在 python 数据类中做瘦(在 python 3.7 + 中引入)。我尝试了下面显示的代码,它给了我一个找不到单元格的异常,
@dataclass
class oxl_cell_dataclass:
cell : oxl.cell.cell.Cell #openpyxl Cell object
xl_column : oxl.cell.cell.Cell.column = cell.column #default value for xl_column attribute
【问题讨论】:
-
这在我看来就像你根本不需要做的事情。
标签: python python-3.7 openpyxl python-dataclasses