def get_declared_attributes(obj, only_names=False):
    """返回对象或类中定义的所有方法和属性"""
    for attr_name, attr_value in vars(obj).iteritems():
        if only_names:
            yield attr_name
        else:
            yield attr_name, attr_value
