python - 使用插槽时要 dict 的数据类
问题描述
如果我使用常规数据类,我可以得到一个 dict
@dataclass
class Cat:
fur: bool
meow: int
Cat(True, 3).__dict__
但是使用的时候就不行了__slots__
。什么是最有效的解决方案?
@dataclass
class Cat:
__slots___ = ['fur', 'meow']
fur: bool
meow: int
# Doesn't work:
Cat(True, 3).__dict__
解决方案
推荐阅读
- javascript - 为什么 Node.js 只识别绝对路径?
- javascript - 更改标题只保存几秒钟(直到页面停止加载)
- django - 位置参数的 Django Rest API 类型错误
- powershell - 创建由 CPU 负载百分比触发的事件侦听器
- c# - 如何根据表 A 中列 A 的结果更新表 B 中的列 b
- javascript - 如何创建在特定条件下转到某个链接的复选框
- python - 如何检查从 Python 到 Neo4j 的连接
- javascript - 数组一直只填充一个对象
- bash - 在没有进入 tnsnames.ora 的情况下执行 sqlplus,独立命令有效并且脚本被击中
- swift - 创建具有 2 种文本颜色的自定义 UI 按钮?