finesse.utilities.tables.Table

Overview

class finesse.utilities.tables.Table(table, headerrow=True, headercolumn=False, color=(-1, -1, -1), backgroundcolor=(-1, -1, -1), alignment='left', compact=False)[source]

Bases: object

Basic class to display tables via pretty printing or html.

This class is a container object for formatted tables. All entries should either be strings or have a __str__ method with readable output. The table can be pretty printed for console and displayed as html. Additionally the table can be saved to a csv file using the same syntax as the csv package or rendered as latex code.

Parameters
tablearray or list

A two dimensional array or list-of-lists containing strings.

headerrowbool, default=True

Whether the first row is a header.

headercolumnbool, default=False

Whether the first column is a header.

colorarray, optional

An array with shape table.shape + (3,) of type int containing RGB color data to control the textcolor. If any value in a RGB triple is negative, no color will be applied to the corresponding cell.

backgroundcolorarray, optional

An array to set the backgroundcolors of the cells, works like color.

alignmentarray, optional

An array with on of (“left”, “center”, “right) for each cell.

compactboolean, optional

Skip internal row separators to save space when printing as string.

Notes

Instead of arrays, color, backgroundcolor and alignment can be given only one option per row, column or total. This will be expanded for the whole table.

Methods

Table.__init__(table[, headerrow, ...])

Table.apply_ansi_colors(text, color, ...)

Add the color codes to the string if necessary.

Table.escape_latex(text)

Replace special characters in latex with their latex representation.

Table.expand_string(text, width[, align])

Expand a string to have a certain length.

Table.generate_grid_table()

Create the whole table.

Table.generate_html_cell(row, column[, style])

Generate html code for the table cell at position (row, column).

Table.generate_html_table()

Table.generate_row(i, start, headerdivision, ...)

Create the `i`th row with the given elements.

Table.generate_seperating_row(start, line, ...)

Generate the string separating two rows.

Table.get_max_column_width(j)

Determine the maximum width of an entry in this column and add 2.

Table.get_visible_length(text)

Get the visible length of the string.

Table.latex()

Make latex code that produces the table.

Table.make_latex_colors()

Define the colors used in the table for latex.

Table.make_latex_str(row, column)

Create latex code for the cell at position (row, column).

Table.print()

Show the table.

Table.write_csv(csvfile[, dialect])

Write the table data to a csv file using the csv package.