common.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:pwtools 作者: elcorto 项目源码 文件源码
def is_seq(seq):
    """Test if `seq` is some kind of sequence, based on calling iter(seq), i.e.
    if the object is iterable.

    Exclude cases which are iterable but that we still don't like: 
        StringTypes = StringType + UnicodeType
        FileType
    UnicodeType is for lists of unicode strings [u'aaa', u'bbb']. In fact, we
    wish to catch list, tuple, numpy array.

    Parameters
    ----------
    seq : (nested) sequence of arbitrary objects
    """ 
    if isinstance(seq, types.StringTypes) or \
       isinstance(seq, types.FileType):
       return False
    else:        
        try:
            x=iter(seq)
            return True
        except:
            return False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号