Skip to content

fluffeliger/tableapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TableAPI

TableAPI is a very simple "API" to create tables in the python console. Its not much but i love this project lmao :)

Getting Started

First things first: Install the latest version with pip here. After this we can staaaarrrrtttttt :D

The import should look something like this

from TableAPI import Table

To write a simple Table, create a table object with the columns and a simple row:

table = Table('A', 'B')
table.add_row('This is', 'a simple test')

Now we have a table, but how do we render it in the console? Well, we have to print the build of the table. Very simple.

print(table.build())

In the console should be a simple table now.

Worst Documentation Ever

Create a Table

There are two ways to create a Table. First one, define the column titles directly in the constructor:

table = Table('A', 'B')

or define the amount of columns and have no titles:

table = Table(2) # Has to be bigger than 0

Build a Table

Simple, it will return a string, which you can print in the console

table = Table('A', 'B')
print(table.build()) # Table#Build() will return the table as a string

Here you go ;)


Define a new Design

Simple as before, change the design of the table with this here:

table.set_theme('|', '-', '+') # Horizontal, Vertical and last one is the dot between

This will display a table with the normal design


Define new Header

It is possible to define a new header with following code snippet:

table.set_header('A', 'B')

NOTE: The amount of strings must match with the amount of columns!


Add a Row

To add a row to a table just write:

table.add_row('A', 'B')

NOTE: The amount of strings must match with the amount of columns!


Remove a Row

To remove a row from a table just write:

table.remove_row(0) # 0 => Row Index

NOTE: Index must be smaller than row size and bigger than zero, else it will return None!


Get a Row Object

There is also a way to get the Row object out of the table. You can write:

table.get_row(0) # 0 => Row Index

NOTE: Index must be smaller than row size and bigger than zero, else it will return None!


Edit a Field

To Edit a Field of a table in a specific row and column, this snippet could help:

table.edit_field(0, 1)  # 0 => Row Index 
						# 1 => Column Index

NOTE: Row-Index must be smaller than the row size and bigger than zero! NOTE: Column-Index must be smaller than the column size and bigger than zero!


Exceptions

There are some exceptions that can come up and here is explained, how you can work with them

InvalidArgSizeException

This Exception will come up if the argument size is not matching a valid pattern. For Example, if you write

table = Table(2, 2)
# or
table = Table()

it will raise this exception, because you can only define 1 column integer or multiple strings. If the Constructor is empty, it doesnt work.


InvalidArgsException

This Exception will raise, if the arguments doesnt match a valid pattern (for example in Table#set_theme)

table.set_theme('', '', '')

This will raise the Exception, because the rule for each argument is: The length has to be exactly 1


InvalidIndexException

This Exception will raise, if the Index on a function that doesnt return something, cannot find a specific Index like this:

table = Table(1)
table.get_row(200) # There is no row 200

The Exception just means, that the index isnt available.


FieldNotFoundException

This Exception will raise, if the field isnt available:

table = Table(1)
table.edit_field(69, 69) # There is no row 69 and column 69

The Exception just means, that the Field on the row-index and column-index isn't available.


Have fun coding <3
~fluffy