def is_iterable(x):
"""Python 3.x adds the ``__iter__`` attribute
to strings. Thus, our previous tests for iterable
will fail when using ``hasattr``.
Parameters
----------
x : object
The object or primitive to test whether
or not is an iterable.
Returns
-------
bool
True if ``x`` is an iterable
"""
if isinstance(x, six.string_types):
return False
return hasattr(x, '__iter__')
评论列表
文章目录