osl_dynamics.utils.model#

Utility classes and functions related to the models.

Module Contents#

Classes#

Table

A simple table class that stores data in rows and columns.

HTMLTable

Class for creating HTML tables.

LatexTable

Class for creating LaTeX tables.

Functions#

tex_escape(text)

Escape characters which require control sequences in text for use

osl_dynamics.utils.model.tex_escape(text)[source]#

Escape characters which require control sequences in text for use in LaTeX.

Parameters:

text (str) – Text to be escaped.

Returns:

escaped_text – Escaped text.

Return type:

str

class osl_dynamics.utils.model.Table(headers)[source]#

A simple table class that stores data in rows and columns.

Parameters:

headers (list) – List of strings for the table headers.

__iadd__(other)[source]#

Add a row to the table.

Parameters:

other (list) – List of values for the row.

Returns:

self – The table object.

Return type:

Table

class osl_dynamics.utils.model.HTMLTable(headers)[source]#

Bases: Table

Class for creating HTML tables.

headers#

The table headers.

Type:

list of str

rows#

The table rows.

Type:

list of list of str

outer = Multiline-String[source]#
Show Value
"""<table>
{headers}
{content}
</table>"""
tr = '<tr>{}</tr>'[source]#
th = '<th>{}</th>'[source]#
td = '<td style="white-space:pre-wrap; word-wrap:break-word">{}</td>'[source]#
append_last(item)[source]#

Append an item to the last cell in the last row.

Parameters:

item (str) – The string to append to the cell.

html_row(items)[source]#

Format a list of strings as an HTML table row.

Parameters:

items (list of str) – A list of str to be added to the HTML table.

Returns:

html – The HTML table row.

Return type:

str

html_headers()[source]#

Generate HTML table headers from self.headers

Returns:

headers – HTML table headers

Return type:

str

output()[source]#

Create the full HTML for the table.

Returns:

html – The HTML for the table.

Return type:

str

_repr_html_()[source]#

Return HTML representation of the current object.

This function is for use by the Jupyter backend.

Returns:

html – HTML representation of the current object.

Return type:

str

class osl_dynamics.utils.model.LatexTable(headers, *, vertical_lines=True, horizontal_lines=True, header_lines=True)[source]#

Bases: Table

Class for creating LaTeX tables.

headers#

The table headers.

Type:

list of str

rows#

The table rows.

Type:

list of list of str

vertical_lines#

Whether to draw vertical lines, by default True.

Type:

bool, optional

horizontal_lines#

Whether to draw horizontal lines, by default True.

Type:

bool, optional

header_lines#

Whether to draw horizontal lines above the header, by default True.

Type:

bool, optional

outer[source]#
escape()[source]#

Escape special characters in headers and rows.

append_last(item)[source]#

Append an item on the last row of the table.

Parameters:

item (any) – Item to append.

static latex_row(items)[source]#

Create a latex row from a list of strings.

Parameters:

items (list of strings) – The list of strings to be turned into a row.

Returns:

latex_row – The latex row.

Return type:

string

output()[source]#

Format the table into LaTeX code.

Returns:

The LaTeX code that produces the table.

Return type:

str

_repr_latex_()[source]#

Returns the LaTeX representation of the object.

Returns:

latex – The LaTeX representation of the object.

Return type:

str