Skip to content

salt-die/tables

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Tables

Pretty print tabular data:

>>> t = Table(
...     [
...         ['John Smith', '356 Grove Rd', '123-4567'],
...         ['Mary Sue', '311 Penny Lane', '555-2451'],
...     ],
...     labels=['Name', 'Address', 'Phone Number'],
... )

>>> print(t)
┌────────────┬────────────────┬──────────────┐
│ NameAddressPhone Number │
├────────────┼────────────────┼──────────────┤
│ John Smith356 Grove Rd123-4567     │
│ Mary Sue311 Penny Lane555-2451     │
└────────────┴────────────────┴──────────────┘
>>> t = Table(
...     [
...         ['spotted','dog','pants','heavily'],
...         ['black','cat','meows','loudly'],
...         ['tall','man','runs','quickly'],
...     ],
...     labels=['adjective','noun','verb','adverb'],
...     centered=True,
...     style='double',
...     padding=3,
... )

>>> print(t)
╔═══════════════╦══════════╦═══════════╦═════════════╗
║   adjectivenounverbadverb    ║
╠═══════════════╬══════════╬═══════════╬═════════════╣
║    spotteddogpantsheavily   ║
║     blackcatmeowsloudly    ║
║     tallmanrunsquickly   ║
╚═══════════════╩══════════╩═══════════╩═════════════╝

>>> t.add_row(['red', 'fox', 'jumped', 'incredibly']); t.add_column(label='article', index=0, default='a'); print(t)
╔═════════════╦═══════════════╦══════════╦════════════╦════════════════╗
║   articleadjectivenounverbadverb     ║
╠═════════════╬═══════════════╬══════════╬════════════╬════════════════╣
║      aspotteddogpantsheavily     ║
║      ablackcatmeowsloudly     ║
║      atallmanrunsquickly     ║
║      aredfoxjumpedincredibly   ║
╚═════════════╩═══════════════╩══════════╩════════════╩════════════════╝

Tables have fancy indexing, table below describes possible keys:

                                 ╷
               key               │                      value
╶────────────────────────────────┼─────────────────────────────────────────────────╴
             `n: int`            │                     row `n`
          `..., m: int`          │                   column `m`
         `n: int, m:int`         │                   cell `n, m`
           `label: str`          │             column labeled `label`
         `ns: list[int]`         │       Table with rows selected from `ns`
       `..., ms: list[int]`      │      Table with columns selected from `ms`
  `ns: list[int], ms: list[int]` │ Table with rows from `ns` and columns from `ms`
       `labels: list[str]`       │  Table with columns with labels from `labels`
                                 ╵

About

Pretty print tabular data.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages