gpt4 book ai didi

python - 是否有 Python 命名元组的替代品

转载 作者:行者123 更新时间:2023-12-04 12:59:28 25 4
gpt4 key购买 nike

Python 官方文档 collections module指出 namedtuple、deque、ChainMap、Counter、OrderedDict、defaultdict、UserDict、UserList 和 UserString 自 Python 3.3 起已被弃用,并将在 Python 3.9 中删除:

Deprecated since version 3.3, will be removed in version 3.9: Moved Collections Abstract Base Classes to the collections.abc module. For backwards compatibility, they continue to be visible in this module through Python 3.8.



我阅读了替换模块的文档: collections.abc .阅读后,我不清楚是否有namedtuple 的替代品。从 Python 3.9 开始,collections.namedtuple 的推荐替代品是什么?

最佳答案

我检查了 Python 版本的文档。 3.8.2 在 https://docs.python.org/3/library/collections.html#collections.namedtuple它绝对不会被弃用。不过,有些功能似乎发生了变化:

Changed in version 3.6: The verbose and rename parameters became keyword-only arguments.

Changed in version 3.6: Added the module parameter.

Changed in version 3.7: Removed the verbose parameter and the _source attribute.

Changed in version 3.7: Added the defaults parameter and the _field_defaults attribute.


正如@CoryKramer 在评论中指出的那样,折旧仅针对 ABC 位。

关于python - 是否有 Python 命名元组的替代品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60440157/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com