When judge the iterable got NameError: name 'Iterable' is not defined

Viewed 3671

I follow the tutorial:

enter image description here

In my PyCharm I follow the tutorial:

enter image description here

I get the error:

Traceback (most recent call last): File "/Users/adob/TestPython/test02/passwd.py", line 19, in bool = isinstance({}, Iterable) NameError: name 'Iterable' is not defined

3 Answers

Python 2:

from collections import Iterable

Python 3:

from collections.abc import Iterable

Or both:

try:
    from collections.abc import Iterable
except ImportError:
    from collections import Iterable
Related