|
1 | | -# Python-Table-Print |
| 1 | +# Python Table Print |
2 | 2 | A project to dynamically scale and print tables using text in Python |
3 | 3 |
|
4 | | -## More documentation to come soon! |
| 4 | +# Usage |
| 5 | + |
| 6 | +Python Table Print is object-oriented. This means that a `PrintTable` object gets instantiated and added to/edited. When the table is ready to be printed/created, this can be done by calling the `print_table`/`get_table` methods. An example can be found in `example.py`, but is copied here for convenience: |
| 7 | + |
| 8 | +```python |
| 9 | +from table import PrintTable |
| 10 | + |
| 11 | +my_table = PrintTable() |
| 12 | + |
| 13 | +my_table.add_row("Col 1", "Col 2", "Col 3") |
| 14 | +my_table.add_row("Entry 1", "Entry number 2", "Entry 3 baby") |
| 15 | +my_table.add_row("Another entry", "yay", "an entry in the table") |
| 16 | +my_table.add_row("Fun times", "This is kinda cool", "wooow") |
| 17 | + |
| 18 | +my_table.print_table() |
| 19 | +``` |
| 20 | + |
| 21 | +Output: |
| 22 | +``` |
| 23 | +************************************************************** |
| 24 | +* Col 1 * Col 2 * Col 3 * |
| 25 | +************************************************************** |
| 26 | +* Entry 1 * Entry number 2 * Entry 3 baby * |
| 27 | +* Another entry * yay * an entry in the table * |
| 28 | +* Fun times * This is kinda cool * wooow * |
| 29 | +************************************************************** |
| 30 | +``` |
| 31 | + |
| 32 | +In the above example, the `print_table` method was called which prints using the default `print` function. However, if the table in string form is preferred, then this is also easily achievable: |
| 33 | + |
| 34 | +```python |
| 35 | +from table import PrintTable |
| 36 | + |
| 37 | +my_table = PrintTable() |
| 38 | + |
| 39 | +... |
| 40 | + |
| 41 | +str_table = my_table.get_table() |
| 42 | +``` |
| 43 | + |
| 44 | +## Header |
| 45 | + |
| 46 | +By default, the first row of the table is treated as the header of the table, and is printed with an extra border around it, not done for any other row. This behaviour can be turned off/on by setting the property `has_header` to `True`/`False`: |
| 47 | + |
| 48 | +```python |
| 49 | +from table import PrintTable |
| 50 | + |
| 51 | +table = PrintTable() |
| 52 | + |
| 53 | +table.add_row("Col 1", "Col 2", "Col 3") |
| 54 | +table.add_row("Entry 1", "Entry number 2", "Entry 3 baby") |
| 55 | +table.add_row("Another entry", "yay", "an entry in the table") |
| 56 | +table.add_row("Fun times", "This is kinda cool", "wooow") |
| 57 | +table.has_header_row = False |
| 58 | + |
| 59 | +table.print_table() |
| 60 | +``` |
| 61 | + |
| 62 | +Output: |
| 63 | +``` |
| 64 | +************************************************************** |
| 65 | +* Col 1 * Col 2 * Col 3 * |
| 66 | +* Entry 1 * Entry number 2 * Entry 3 baby * |
| 67 | +* Another entry * yay * an entry in the table * |
| 68 | +* Fun times * This is kinda cool * wooow * |
| 69 | +************************************************************** |
| 70 | +``` |
0 commit comments