Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(2)  |  Call(1)  |  Derive(0)  |  Import(1)

        def is_iterable(maybe):
    '''Returns True if `maybe` is an iterable object (e.g. implements the
    `__iter__` method):

    ::

        >>> is_iterable('all strings are iterable')
        True

        # Numbers are not
        >>> is_iterable(1)
        False

        >>> is_iterable(xrange_(1))
        True

        >>> is_iterable({})
        True

        >>> is_iterable(tuple())
        True

        >>> is_iterable(set())
        True

    '''
    try:
        iter(maybe)
    except:
        return False
    else:
        return True
        


src/x/o/xoutil-1.5.4/xoutil/json.py   xoutil(Download)
    def default(self, o):
        from decimal import Decimal as _Decimal
        from xoutil.types import is_iterable
        from xoutil.datetime import (is_datetime as _is_datetime,
                                     new_datetime as _new_datetime,
        elif isinstance(o, _Decimal):
            return str(o)
        elif is_iterable(o):
            return list(iter(o))
        return super(JSONEncoder, self).default(o)