Language/Python
[beautifultable] Print List in Table Format
See_the_forest
2022. 9. 14. 11:04
1. What is BeautifulTable?
This package provides BeautifulTable Class for easily printing tabular data in a visually appealing format to a terminal.
Features included but not limited to :
- Full customization of the look and the feel of the table
- Build the table as you wish, by adding rows, or by columns or even mixing both these approaches.
- Full support for colors using ANSI sequences or any library of your choice. It just works.
- Plenty of predefined styles for multiple use cases and option to create custome ones.
- Support for Unicode characters.
- Supports streaming table when data is slow to retrieve.
2. How to use
Step 1 : Import libraries and make objects
from beautifultable import BeautifulTable
table = BeautifulTable(maxwidth = 130)
You can control maxwidth with 'maxwidth' parameter.
Step 2 : Add columns and rows
You can add rows by using append_row method until you want to end.
table.column_headers = laptops.header
# Find laptops under 500 euros
for laptop in laptops.find_laptop_within('Price_euros', 200):
table.append_row(laptop)
print(table)