鱼C论坛

 找回密码
 立即注册
查看: 2289|回复: 3

[已解决]import collections模块python说不推荐使用,那他推荐的模块是哪个呢?

[复制链接]
发表于 2021-5-30 23:20:55 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
我导入import collections时,系统说不推荐,但我再次调用却还是能正常使用
不推荐使用警告:从“collections”而不是从“collections.abc”中使用或导入abc在python3.3中已不推荐使用,在3.10中它将停止工作
那现在推荐导入哪个模块呢,能用isinstance检测是否是可迭代

  1. >>> import collections as g
  2. >>> list1 = [1,2,3,4,5,6]
  3. >>> f = isinstance(list1,g.Iterable)

  4. Warning (from warnings module):
  5.   File "<pyshell#2>", line 1
  6. DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.10 it will stop working
  7. >>> f = isinstance(list1,g.Iterable)
  8. >>> f
  9. True
  10. >>>
复制代码
最佳答案
2021-5-31 00:12:00
from collections.abc import xxx
例如
  1. from collections.abc import Iterator
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-5-31 00:12:00 | 显示全部楼层    本楼为最佳答案   
from collections.abc import xxx
例如
  1. from collections.abc import Iterator
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-5-31 12:33:45 | 显示全部楼层
检测是否是可迭代为什么不用typing模块  from typing import Callable, Iterable, Iterator
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-5-31 15:54:02 | 显示全部楼层
kogawananari 发表于 2021-5-31 12:33
检测是否是可迭代为什么不用typing模块  from typing import Callable, Iterable, Iterator

谢谢解答,我刚学到魔法方法那章,还在学
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-23 05:33

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表