是否有一个很好的一站式 Python 参考来选择与 hasattr() 一起使用的属性来识别类型。
例如,以下是不是字符串的序列:
def is_sequence(arg):
    return (not hasattr(arg, "strip") and
            hasattr(arg, "__getitem__") or
            hasattr(arg, "__iter__")) 
最好有一个可靠的参考来快速选择最佳模式。
使用集合模块中已经为您编写的虚拟子类( Python 3.3 中的collections.abc)。
要检查某个东西是否是非字符串序列,请使用
from collections import Sequence    # collections.abc in Python 3.3
isinstance(arg, Sequence) and not isinstance(arg, basestring)    # str in Python 3
    使用适当的抽象基类:
import collections
isinstance([], collections.Sequence) # ==> true