python 导包警告 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
代码如下(示例):
from collections import Iterator
print(isinstance(iter([]), Iterator)) # True
# 控制台输出:
# D:\Code_data\pycharm project\first test\08-iterable.py:2: 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
# from collections import Iterator
# True
虽然结果出来了,但是一直有个烦人的警告(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),不仔细看,还以为代码哪里报错了
解决办法就是将
from collections import Iterator
改为
from collections.abc import Iterator
本文介绍了解决Python 3.3及以上版本中关于从'collections'导入ABCs的DeprecationWarning,指导读者如何修正代码以避免未来兼容问题。
9206

被折叠的 条评论
为什么被折叠?



