def get_nested_attr(obj, attr, default=None):
    """Get nested attributes of an object."""
    attrs = attr.split(".")
    for a in attrs:
        try:
            obj = getattr(obj, a)
        except AttributeError:
            if default:
                return default
            else:
                raise
    return obj