Convert 2D Python lists into Unicode/Ascii tables
Project description
table2ascii
Module for converting 2D Python lists to a fancy ASCII/Unicode tables
๐ฅ Installation
pip install table2ascii
๐งโ๐ป Usage
Convert Python lists to ASCII tables
from table2ascii import table2ascii
output = table2ascii(
header=["#", "G", "H", "R", "S"],
body=[["1", "30", "40", "35", "30"], ["2", "30", "40", "35", "30"]],
footer=["SUM", "130", "140", "135", "130"],
)
print(output)
"""
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ # G H R S โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโข
โ 1 30 40 35 30 โ
โ 2 30 40 35 30 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโข
โ SUM 130 140 135 130 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
"""
from table2ascii import table2ascii
output = table2ascii(
body=[["Assignment", "30", "40", "35", "30"], ["Bonus", "10", "20", "5", "10"]],
first_col_heading=True,
)
print(output)
"""
โโโโโโโโโโโโโโฆโโโโโโโโโโโโโโโโโโโโ
โ Assignment โ 30 40 35 30 โ
โ Bonus โ 10 20 5 10 โ
โโโโโโโโโโโโโโฉโโโโโโโโโโโโโโโโโโโโ
"""
from table2ascii import table2ascii, Alignment
output = table2ascii(
header=["#", "G", "H", "R", "S"],
body=[["1", "30", "40", "35", "30"], ["2", "30", "40", "35", "30"]],
first_col_heading=True,
column_widths=[5] * 5, # [5, 5, 5, 5, 5]
alignments=[Alignment.LEFT] + [Alignment.RIGHT] * 4, # First is left, remaining 4 are right
)
print(output)
"""
โโโโโโโฆโโโโโโโโโโโโโโโโโโโโโโโโ
โ # โ G H R S โ
โโโโโโโซโโโโโโโโโโโโโโโโโโโโโโโโข
โ 1 โ 30 40 35 30 โ
โ 2 โ 30 40 35 30 โ
โโโโโโโฉโโโโโโโโโโโโโโโโโโโโโโโโ
"""
โ๏ธ Options
All parameters are optional.
Soon table2ascii will support more options for customization.
Option | Type | Default | Description |
---|---|---|---|
header |
List |
None |
First row of table seperated by header row seperator |
body |
2D List |
None |
List of rows for the main section of the table |
footer |
List |
None |
Last row of table seperated by header row seperator |
column_widths |
List |
automatic | List of column widths in characters for each column |
alignments |
List |
all centered | Alignments for each column (ex. [Alignment.LEFT, Alignment.CENTER, Alignment.RIGHT] ) |
first_col_heading |
bool |
False |
Whether to add a heading column seperator after the first column |
last_col_heading |
bool |
False |
Whether to add a heading column seperator before the last column |
๐จโ๐จ Use cases
Discord messages and embeds
- Display tables nicely inside markdown codeblocks on Discord
- Useful for making Discord bots with Discord.py
Terminal outputs
- Tables display nicely whenever monospace fonts are fully supported
- Tables make terminal outputs look more professional
๐งฐ Development
To run tests (pytest)
python setup.py test
To lint (flake8):
python setup.py lint
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
table2ascii-0.0.3.tar.gz
(7.9 kB
view hashes)
Built Distribution
Close
Hashes for table2ascii-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fd18077fe9b91afa27386f1134f38fccd80a16dd2e599d33e30e0080d78d0c3 |
|
MD5 | 9f006605fc8db049672e27290341a4cd |
|
BLAKE2b-256 | 60964083835ce3ce806e92169ab5fe72426dd1b2fcfcc8e1d690a9502dd1a4e6 |