def flatten_obj(obj, fields, *, rest_val=None):
    """
    >>> class A: pass
    >>> a = A(); a.a = 1; a.b=2
    >>> flatten_obj(a, ('a', 'b'))
    [1, 2]

    >>> flatten_obj(a, ('a', 'b', 'c'))
    Traceback (most recent call last):
        ...
    AttributeError: 'A' object has no attribute 'c'

    >>> flatten_obj(a, ('a', 'b', 'c'), rest_val=5)
    [1, 2, 5]
    """
    if rest_val is not None:
        return [getattr(obj, f, rest_val) for f in fields]
    return [getattr(obj, f) for f in fields]