(tables, id_label='id', separator='.', include_headers=True,
                   include_data=True)
return answ
tables nested dict structure from _create_intermediate_tables
    return [
        (table_name, [
            (FormattedRow(headers, [id_label], separator) if include_headers),
            FormattedRow(values, id, separator),
            FormattedRow(values, id, separator),
            ...
        ])
    ]
tables nested dict structure from _create_intermediate_tables
    return [
        (table_name, [
            (FormattedRow(headers, [id_label], separator) if include_headers),
            FormattedRow(values, id, separator),
            FormattedRow(values, id, separator),
            ...
        ])
    ]
tables nested dict structure from _create_intermediate_tables return [ ( table_name [ ( FormattedRow ( headers [ id_label ] separator ) if include_headers ) FormattedRow ( values id separator ) FormattedRow ( values id separator ) ... ] ) ]
def _format_tables(tables, id_label='id', separator='.', include_headers=True,
                   include_data=True):
    """
    tables nested dict structure from _create_intermediate_tables
    return [
        (table_name, [
            (FormattedRow(headers, [id_label], separator) if include_headers),
            FormattedRow(values, id, separator),
            FormattedRow(values, id, separator),
            ...
        ])
    ]

    """
    answ = []
    assert include_data or include_headers, "This method is pretty useless if you don't include anything!"

    for table_name, table in sorted(tables.items()):
        new_table = []
        keys = sorted(list(table.items())[0][1])  # the keys for every row are the same

        if include_headers:
            id_key = [id_label]
            id_len = len(list(table)[0])  # this is a proxy for the complexity of the ID
            if id_len > 1:
                id_key += ["{id}__{count}".format(id=id_label, count=i) for i in range(id_len)]
            header_vals = [separator.join(key) for key in keys]
            new_table.append(FormattedRow(header_vals, id_key, separator,
                                          is_header_row=True))

        if include_data:
            for id, row in sorted(table.items()):
                values = [row[key] for key in keys]
                new_table.append(FormattedRow(values, id, separator))

        answ.append((separator.join(table_name), new_table))
    return answ
def _format_tables ( tables , id_label = 'id' , separator = '.' , include_headers = True , include_data = True ) : answ = [ ] assert include_data or include_headers , "This method is pretty useless if you don't include anything!" for table_name , table in sorted ( tables . items ( ) ) : new_table = [ ] keys = sorted ( list ( table . items ( ) ) [ 0 ] [ 1 ] ) # the keys for every row are the same if include_headers : id_key = [ id_label ] id_len = len ( list ( table ) [ 0 ] ) # this is a proxy for the complexity of the ID if id_len > 1 : id_key += [ "{id}__{count}" . format ( id = id_label , count = i ) for i in range ( id_len ) ] header_vals = [ separator . join ( key ) for key in keys ] new_table . append ( FormattedRow ( header_vals , id_key , separator , is_header_row = True ) ) if include_data : for id , row in sorted ( table . items ( ) ) : values = [ row [ key ] for key in keys ] new_table . append ( FormattedRow ( values , id , separator ) ) answ . append ( ( separator . join ( table_name ) , new_table ) ) return answ