Skip to main content
Version: 0.5.x

TableFormatter

Format tabular data into strings for display in the console.

Module: aisp.utils.display
Import: from aisp.utils.display import TableFormatter


Constructor Parameters

NameTypeDefaultDescription
headersMapping[str, int]-Mapping of column names to their respective widths, in the format {column_name: column_width}.

Public Methods

get_header

def get_header(self):
...

Generate the table header, including the top border, column headings, and separator line.

Returns

TypeDescription
strFormatted string of the table header.

get_row

def get_row(self, values: Mapping[str, Union[str, int, float]]):
...

Generate a formatted row for the table data.

Parameters

NameTypeDefaultDescription
valuesMapping[str, Union[str, int, float]]-Dictionary with values for each column, in the format {column_name: value}.

Returns

TypeDescription
strFormatted string of the table row.

get_bottom

def get_bottom(self, new_line: bool = False):
...

Generate the table's bottom border.

Parameters

NameTypeDefaultDescription
new_lineboolFalseIf True, adds a line break before the border (default is False).

Returns

TypeDescription
strFormatted string for the bottom border.