API Reference
table2ascii
- table2ascii.table2ascii(header: Optional[List] = None, body: Optional[List[List]] = None, footer: Optional[List] = None, **options) str
Convert a 2D Python table to ASCII text
- Parameters
header (
Optional[List]
) – List of column values in the table’s header rowbody (
Optional[List[List]]
) – 2-dimensional list of values in the table’s bodyfooter (
Optional[List]
) – List of column values in the table’s footer rowstyle (
TableStyle
) – Table style to use for styling (preset styles can be imported)column_widths (
List[int]
) – List of widths in characters for each column (defaults to auto-sizing)alignments (
List[Alignment]
) – List of alignments (ex. [Alignment.LEFT, Alignment.CENTER, Alignment.RIGHT])first_col_heading (
bool
) – Whether to add a header column separator after the first columnlast_col_heading (
bool
) – Whether to add a header column separator before the last column
- Returns
The generated ASCII table
- Return type
str
Alignment
PresetStyle
- class table2ascii.PresetStyle
Importable preset styles for more easily selecting a TableStyle.
See the Preset Styles for more information on the available styles.
Example:
from table2ascii import PresetStyle output = table2ascii( ... style=PresetStyle.ascii_box )
TableStyle
- class table2ascii.TableStyle(top_left_corner: str, top_and_bottom_edge: str, heading_col_top_tee: str, top_tee: str, top_right_corner: str, left_and_right_edge: str, heading_col_sep: str, col_sep: str, heading_row_left_tee: str, heading_row_sep: str, heading_col_heading_row_cross: str, heading_row_cross: str, heading_row_right_tee: str, row_left_tee: str, row_sep: str, heading_col_row_cross: str, col_row_cross: str, row_right_tee: str, bottom_left_corner: str, heading_col_bottom_tee: str, bottom_tee: str, bottom_right_corner: str)
Class for storing information about a table style
Parts of the table labeled alphabetically:
ABBBBBCBBBBBDBBBBBDBBBBBDBBBBBE F G H H H F IJJJJJKJJJJJLJJJJJLJJJJJLJJJJJM F G H H H F NOOOOOPOOOOOQOOOOOQOOOOOQOOOOOR F G H H H F IJJJJJKJJJJJLJJJJJLJJJJJLJJJJJM F G H H H F SBBBBBTBBBBBUBBBBBUBBBBBUBBBBBV
How the theme is displayed with double thickness for heading rows and columns and thin for normal rows and columns:
╔═════╦═════╦═════╦═════╦═════╗ ║ # ║ G │ H │ R │ S ║ ╠═════╬═════╪═════╪═════╪═════╣ ║ 1 ║ 30 │ 40 │ 35 │ 30 ║ ╟─────╫─────┼─────┼─────┼─────╢ ║ 2 ║ 30 │ 40 │ 35 │ 30 ║ ╠═════╬═════╪═════╪═════╪═════╣ ║ SUM ║ 130 │ 140 │ 135 │ 130 ║ ╚═════╩═════╩═════╩═════╩═════╝
- classmethod from_string(string: str) table2ascii.table_style.TableStyle
Create a TableStyle from a string
- Parameters
string – The string to create the TableStyle from
- Returns
A TableStyle object
- Return type
Example:
TableStyle.from_string("╔═╦═╗║║ ╟─╫─╢ ╚╩═╝")