ascii tables in python 1

ascii tables in python

# pip install -U table2ascii

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 ║
╚═════════════════════════════╝

Here is what the above code is Doing:
1. Import the table2ascii module
2. Create a table2ascii object
3. Print the output

The table2ascii object takes the following arguments:

header: A list of strings that will be used as the header of the table.
body: A list of lists of strings that will be used as the body of the table.
footer: A list of strings that will be used as the footer of the table.

Similar Posts