def get_deep_name(name, mode='_'):
    """
    Returns name transformed by mode. If mode is '_' dots in name are 
    replaced by underscores, and if it is 'last', only the part after the 
    rightmost dot is used as name.

    Arguments:
      - name: attribute name
      - mode: determines how a name containing dots is transformed 
    """

    if mode == '_':
        name = name.replace('.', '_')

    elif mode == 'last':
        attributes = name.split('.')
        name = attributes.pop()

    else:
        raise ValueError("Argument mode can be '_', or 'last' but not " + mode)

    return name