tabulardelta.formatters.tabulartext.table module
- class tabulardelta.formatters.tabulartext.table.Border(style_specifier: str)[source]
Bases:
objectImplementation of
BorderStyle, for adding a border to an existing table.- Offers out-of-the-box border styles as class attributes:
Nothing,InnerGap,Basic, andVerticalGap.- Use
__init__()withstyle_specifierfor specialized border styles: A style specifier are comma-separated border descriptions, for all 19 border positions.
Border descriptions start with a space or a dot, followed by the content of the border cell.
A dot means that the border cell is allowed to have size 0, a space means it is not.
The style specifier for
Basictherefore looks like this:┏,.━, ┯, ┓,.│, ┠, ┬, ┤,.┃,.─, .┃, ├, ┴, ┨, ┼, ┗, ┷,.━, ┛
Methods
__init__(self, style_specifier: str):
Initializes a
Borderbased on style specifier__call__(self, table: Table) -> list[list[Cell]]:
Implements
BorderStyle- Basic: ClassVar[BorderStyle] = <tabulardelta.formatters.tabulartext.table.Border object>
Uses box-drawing characters to draw a beautiful border.
- InnerGap: ClassVar[BorderStyle] = <tabulardelta.formatters.tabulartext.table.Border object>
Adds empty lines between rows and two spaces between columns.
- Nothing: ClassVar[BorderStyle] = <tabulardelta.formatters.tabulartext.table.Border object>
Empty border cells.
Can be used as syntactic sugar to not always specify add_border=False.
- VerticalGap: ClassVar[BorderStyle] = <tabulardelta.formatters.tabulartext.table.Border object>
Adds two spaces between columns.
- class tabulardelta.formatters.tabulartext.table.BorderStyle(*args, **kwargs)[source]
Bases:
ProtocolBorderStyle is a protocol for adding border-cells in-between existing cells of a table.
- Arguments:
- table
Table: Table to add borders to.
- table
- Returns
list[list[Cell]]: Table content with added border cells.
Methods
__call__(self, table: Table) -> list[list[Cell]]:
Adds border to given table
- class tabulardelta.formatters.tabulartext.table.Table(content: list[list[~tabulardelta.formatters.tabulartext.cell.Cell]], border: ~tabulardelta.formatters.tabulartext.table.BorderStyle = <tabulardelta.formatters.tabulartext.table.Border object>, _border_added: bool = False)[source]
Bases:
objectRepresents a table containing cells with a border style.
- Note:
If you don’t have a
list[list[Cell]], tryfrom_lists()to create a table.This will cast the content accordingly (see
from_lists()documentation).
Methods
__getitem__(self, item: int) -> list[Cell]:
Retrieves cells using
table[row_nr][col_nr].__setitem__(self, key: int, value: list[Cell]) -> None:
Setting cells using
table[row_nr][col_nr] = cell.from_lists(strs: list[list[Any]], border: BorderStyle = Border.Basic) -> Table:
Casts content to create table (see
from_lists()documentation).lines(self, add_border: bool = True) -> list[str]:
Renders table as line-separated list of strings.
to_string(self, add_border: bool = True) -> str:
Renders table as string.
__str__(self) -> str:
Renders table as string.
- border: BorderStyle = <tabulardelta.formatters.tabulartext.table.Border object>
Border style to be added.
- static from_lists(strs: list[list[~typing.Any]], border: ~tabulardelta.formatters.tabulartext.table.BorderStyle = <tabulardelta.formatters.tabulartext.table.Border object>) Table[source]
Creates a table from list of lists of objects, where each object is cast to a cell:
A
Cellwon’t be casted.A
listis interpreted as containing lines, with each line being casted tostr.Other objects are casted to strings.
- Arguments:
- strs
list[list[Any]]: List of lists of cell objects.
- border
BorderStyle: Border style of table.
- strs
- Returns
Table: Table containing casted cells and border style.
- lines(add_border: bool = True) list[str][source]
Returns rendered table as line-separated list of strings.
This method will never add a border if it already exists!
- Arguments:
- add_border
bool: Whether to add a border to the table.
- add_border
- Returns
list[str]: Line-separated rendered table.
- to_string(add_border: bool = True) str[source]
Returns rendered table as string by concatenating
lines().This method will never add a border if it already exists!
__str__()calls this method with default arguments.- Arguments:
- add_border
bool: Whether to add a border to the table.
- add_border
- Returns
str: Rendered table.