Print tables directly in the terminal
Project description
Console-Table
Displaying Tables in the console
How To Use
# Import package
from cli_table import Table, align_data_left, align_data_center, align_data_right
# Create some data
data = [
['First Name', 'Last Name', 'Grade'],
['Roy', 'Trenneman', 5],
['Maurice', 'Moss', 1],
['Jen', 'Barber', 6],
['Douglas', 'Reynholm', 9],
['Richmond', 'Avenal', 7],
]
# Create the table
table = Table(
data,
alignment=align_data_left,
header_alignment=align_data_center,
header=True,
)
# Sort by specific rows
table.sort_by('Grade')
# Freeze the table
table.freeze()
# Print the table
print(table)
Output:
| First Name | Last Name | Grade |
| Maurice | Moss | 1 |
| Roy | Trenneman | 5 |
| Jen | Barber | 6 |
| Richmond | Avenal | 7 |
| Douglas | Reynholm | 9 |
Arguments
Table()
Creates a table object
Argument | Type | Default Value | Description |
---|---|---|---|
data |
list[list[Any]] |
2D array containing the data to be used | |
margin= |
int |
1 |
Margin around cells, (how many spaces before and after data) |
alignment= |
align_data_left | align_data_center | align_data_right |
align_data_center |
How to align data |
header_alignment= |
align_data_left | align_data_center | align_data_right |
align_data_center |
How to align headers |
header= |
bool |
False |
Does the data contain a header (0th row is the header) |
add_top= |
bool |
False |
Add a top border around the table |
add_bottom= |
bool |
False |
Add a bottom border around the table |
use_color= |
bool |
False |
Use colorama colors for the table |
header_color_bg= |
str |
colorama.Back.RESET |
Header Background Color |
header_color_fg= |
str |
colorama.Fore.LIGHTBLUE_EX |
Header Foreground Color |
odd_color_bg= |
str |
colorama.Back.RESET |
Odd Numbered Cells Background Color |
odd_color_fg= |
str |
colorama.Fore.BLUE |
Odd Numbered Cells Foreground Color |
even_color_bg= |
str |
colorama.Back.RESET |
Even Numbered Cells Background Color |
even_color_fg= |
str |
colorama.Fore.CYAN |
Even Numbered Cells Foreground Color |
Table().is_frozen()
Checks if the table needs to be frozen before printing
Table().sort_by()
Sorts the table by the values of a column
Argument | Type | Default Value | Description |
---|---|---|---|
column |
str | int |
Which column index(int) or name(str) to sort by | |
key= |
None | Callable |
None |
Sorting key, takes the entire row, should return a sortable value, bu default, returns the entire cell |
reverse= |
bool |
False |
Reverses the sorting algorithm, asc or desc |
Table().update_data()
Changes the data that the table has
Argument | Type | Default Value | Description |
---|---|---|---|
data |
list[list[Any]] |
New data to be used |
Table().freeze()
Compiles the given data into a string for quick displaying
Table().display() | print(Table())
Prints the table
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
Built Distribution
Close
Hashes for hamolicious-cli-table-1.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68305a50b408bc23431c547f76c57dc510ce47bca3927f730036ef8b0f5fd9de |
|
MD5 | a9bf71d7e48571f3e8911baf0d3d69a6 |
|
BLAKE2b-256 | 1aee20bdbe9da6ae3a8a54a59c354359b81970531de04e59681acab931873aed |
Close
Hashes for hamolicious_cli_table-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc5d6dbcb49291f8afb2154a43efd13e505df9115bd345b5e7ae7d69daad2dae |
|
MD5 | 708f3f4d62cdaddacc07185055cf329a |
|
BLAKE2b-256 | 0eeda67e61ae116dc74c926ac466b84b2f57a0629f9f10e83721a2ca3c28b20f |