jdutable
Command line table data visualisation tool.
Installation
> pip(3) install (-U) jdutable
and
from jdutable import TableWriter
Instantiation
table = TableWriter()
Methods
Add data
def set_header(self, header: list[str])
... to add a list of strings as the header of the table.
def set_footer(self, footer: list[str])
... to add a list of strings as the footer of the table.
def append(self, line:list[str])
... to add a line of strings to the content of the table.
def append_bulk(self, data: list[list[str]])
... to add multiple lines to the content of the table.
def from_csv(self, filename: Path, header: bool = False, footer: bool = False, sep: str = ",")
... to import a csv file. The parameter are:
- filename: path to the csv file to import
- header: boolean to tell if csv file contains a header
- footer: boolean to tell if csv file contains a footer
- sep: string defining what the csv delimiter is
Parameters
def set_uppercased(self, state: bool)
... to print the header and footer with uppercased letters.
def set_border(self, state: bool)
... to show a border around the table.
def set_alignment(self, alignment: str or list[str])
... to define alignment guide for each column. Alignement can be a single string defining alignment for all columns, or a list of strings specifying the alignment guide for each column. To align to the:
- left: either "<", "left" or "l"
- center: either "^", "center" or "c"
- right: either ">", "right" or "r"
def set_center_separator(self, separator: str)
... to change the table lines intersection character.
def set_column_separator(self, separator: str)
... to change the table vertical lines character.
Display
def render(self, file=sys.stdout)
... to render the table using previously specified content, header/footer and parameters. file parameter can be add to write the table to a file, or a different standard output.
Reset
def reset_header(self)
... to reset the header to an empty list.
def reset_body(self)
... to reset the body to an empty list.
def reset_footer(self)
... to reset the footer to an empty list.
def reset_content(self)
... to reset header, body, and footer to an empty list.
Example
Let's use the following content, that is in file assets/example.csv:
Date, Description, Amout
1/1/2014, Domain name, $10.98
1/1/2014, January Hosting, $54.95
1/4/2014, February Hosting, $51.00
1/4/2014, February Extra Bandwidth, $30.00
, Total, $146.93
Heres an example code to render this file:
from pathlib import Path
from jdutable import TableWriter
table = TableWriter()
table.from_csv(Path("assets/example.csv"), header=True, footer=True)
table.set_uppercased(False)
table.set_border(True)
table.set_alignment(["left", "<", "r"])
table.set_center_separator("-")
table.set_column_separator("|")
table.render()
This shows the following result in the command line:
---------------------------------------------------
! Date ! Description ! Amout !
---------------------------------------------------
! 1/1/2014 ! Domain name ! $10.98 !
! 1/1/2014 ! January Hosting ! $54.95 !
! 1/4/2014 ! February Hosting ! $51.00 !
! 1/4/2014 ! February Extra Bandwidth ! $30.00 !
---------------------------------------------------
Total $146.93
----------------------------------------
Release files for jdutable 0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| jdutable-0.4.tar.gz | 6.1 kB | Details |
Release files / jdutable-0.4.tar.gz
| Download URL | jdutable-0.4.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c199e8a81ad73d187b1612b43d2d6bc65c2484bb5309b6bcf276c2ccea7fba49
|
|
BLAKE2b-256 checksum How to use checksums |
8f1db08036e20f791fb2e33f985e3299c14dfe8234bc0a777412034a9f980e67
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|