下面的这段代码在执行时出现了错误,
from collections import Iterable
from collections import Iterator
print(isinstance([], Iterator))
print(isinstance([], Iterable))
DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import Iterable
从错误的描述中可以看出是导入的错误,因此,需要改变导入的方式。改变方式如下:
from collections.abc import Iterable
from collections.abc import Iterator
print(isinstance([], Iterator))
print(isinstance([], Iterable))