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
评论列表
文章目录