* sugar: Added is_iterable().

This commit is contained in:
Wirawan Purwanto
2012-03-19 11:57:19 -04:00
parent 14303979f1
commit 41079fd92c

View File

@@ -13,6 +13,15 @@
import sys
import weakref
def is_iterable(x):
"""Checks if an object x is iterable.
It checks only for the presence of __iter__, which must exist for
container objects.
Note: we do not consider non-containers such as string and unicode as
`iterable'; this behavior is intended.
"""
return hasattr(x, "__iter__")
def ifelse(cond, trueval, *args):
"""An alternative to python's own ternary operator, but with multiple
conditions to test (like chained if-else-if-else... which is found in