In Python, how do I determine if an object is iterable?
Checking for __iter__ works on sequence types, but it would fail on e.g. strings in Python 2. I would like to know the right answer too, until then, here is one possibility (which would work on strings, too): from __future__ import print_function try: some_object_iterator = iter(some_object) except TypeError as te: print(some_object, ‘is not iterable’) The … Read more