Skip to main content

An easy to use console based table

Project description

EasyTable

The goal of EasyTable is to provide a python module that allows people to easily create a table, change its appearance and add data, and allow them to not to have to worry about resizing the table to nicely fit their data. The EasyTable was made by Jacob Rumbolt aka 'TheGuyFromCanada' or 'TheCanadian'

Using EasyTable

Easytable has a few functions that need to be called to create the table, below is sample code to create a table

First off import the EasyTable module and create and instance of it

import easy_table

myTable = easy_table.EasyTable()

Next set characters for the struture of the table. The parameters for the functions goes as follows:

setTableCorners(top left, top right, bottom right, bottom left) setTableBorder(vertical border, horizontal border) setTableInnerStructure(vertical, horizontal, intersection)

myTable.setTableCorners("/", "\\", "/", "\\")
myTable.setTableBorder("|", "-")
myTable.setTableInnerStructure("|", "-", "+")

Now set the column titles and data, setColoumns takes an array of strings, and setData takes a 2D array of strings. The parameters are as follows:

setColumns(column title array) setData(data array)

myTable.setColumns(["ID #", "Name", "Age"])
data = [["0","Jeff","31"],["1","Bill", "22"], ["2", "Tim", "33"], ["3", "Timothy", "41"]]
myTable.setData(data)

Finally the only thing left is to display the table

myTable.displayTable()

Below is what the table would look like:

/----------------\
|ID #|  NAME |AGE|
|----+-------+---|
| 0  |  Jeff | 31|
|----+-------+---|
| 1  |  Bill | 22|
|----+-------+---|
| 2  |  Tim  | 33|
|----+-------+---|
| 3  |Timothy| 41|
\----------------/

If you want to sort the table use sortTable(sortPos) and give it the position of the column the table will be sorted off of, for example to sort the table above based off the ages include the following code

myTable.sortTable(2)

In the code above 2 passed for sortPos because the age column is in the second position of the column title array. The sorted table would look like

/----------------\
|ID #|  NAME |AGE|
|----+-------+---|
| 1  |  Bill | 22|
|----+-------+---|
| 0  |  Jeff | 31|
|----+-------+---|
| 2  |  Tim  | 33|
|----+-------+---|
| 3  |Timothy| 41|
\----------------/

If you want to search through the table use searchTable(array, column_num, search_term) and give it the array to search in, the column to search within and the value to search for

search_result = myTable.searchTable(data, 1, "Tim")
myTable.setData(search_result)

In the code above data is the array of data, 1 is the name column within the array and Tim is the term being searched for, the array returned is an array containing the rows of data where the name column has a value containing Tim

/----------------\
|ID #|  NAME |AGE|
|----+-------+---|
| 2  |  Tim  | 33|
|----+-------+---|
| 3  |Timothy| 41|
\----------------/

In case you want to see the characters used in the table call showTableProps(), this will prodice the following:

----TABLE PROPERTIES----
Table Corners: / \ / \
Table Border: | -
Table Inner Structure: | - +

License

The EasyTable project is licensed under the MIT License - see LICENSE

Project details


Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
easy_table-3.0.0-py3-none-any.whl (4.7 kB) Copy SHA256 hash SHA256 Wheel py3
easy_table-3.0.0.tar.gz (4.3 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page