tabular_report#

class arte.utils.tabular_report.TabularReport(column_names, decimation: int = 1, hdr_decimation: int = 100, add_iter: bool = True, column_width: int = 10, iteration_hdr='iteration')#

Bases: object

Report with column-based format.

Prints a new line of values each time it is triggered.

Columns are defined at initialization with the column_names, and they can be set using the [] operator. Each column will occupy column_width characters (default 10 characters). Columns will be printed in the order they were added.

Each column has a formatter function, which can set using the .fmt dictionary. The formatter function must take a single parameter, the value to be displayed, and return a string. By default, all columns are formatted with str().

It is possible to add a column on the fly assigning to it using the [] operator. The new column will be assigned the default str() formatter.

Every time the report() function is called, an internal counter is incremented and, if at least decimation counts have passed since the last time, the values are printed on stdout. By default, decimation is 1 and all lines are printed. A header with the column names is printed before the first line and after each repeat_hdr lines have been printed (default 100). If add_iter is True, the counter is printed as the first column.

decimation#

how many calls to report() are needed before a line is printed

Type:

int

hdr_decimation#

how many lines are printed before the header is printed again

Type:

int

add_iter#

if True, the iteration number is added as the first column

Type:

bool

column_width#

number of characters assigned to each column

Type:

int

iteration_hdr#

string used as column name for the iteration number

Type:

str

['column_name']

Assign values to column using the [] operator.

fmt[]#

Assign special formatting functions using the fmt dictionary.

Examples

>>> from arte.utils.tabular_report import TabularReport
>>> r = TabularReport(['pippo','pluto'])
>>> for i in range(2):
...    r['pippo'] = i*2
...    r['pluto'] = i+10
...    r.report()
>>> r['paperino'] = 'a'
>>> r.fmt['paperino'] = ord
>>> r.print_header()
>>> r.report()

Result:

.. rubric:: Methods

print_header()

Unconditionally print a line with the header.

print_line()

Unconditionally print a line with all the current values

report()

Increment the iteration counter and if, conditions match, print a header and/or a line of values.

print_header()#

Unconditionally print a line with the header.

print_line()#

Unconditionally print a line with all the current values

report()#

Increment the iteration counter and if, conditions match, print a header and/or a line of values.