astanin / python-tabulate

Pretty-print tabular data in Python, a library and a command-line utility. Repository migrated from bitbucket.org/astanin/python-tabulate.
https://pypi.org/project/tabulate/
MIT License
2.1k stars 163 forks source link

Sub headings would be a great feature #254

Open pwhipp opened 1 year ago

pwhipp commented 1 year ago

This is an excellent python utility. I'd use it a lot more if I could have sub headings. Here's an example:

I have this table:

| site   | name   | primary.database_host   | primary.database_port   | primary.host    | primary.port   | primary.state   | primary.status   | replica.database_host   | replica.database_port   | replica.host   | replica.port   | replica.state   | replica.status   |
|--------|--------|-------------------------|-------------------------|-----------------|----------------|-----------------|------------------|-------------------------|-------------------------|----------------|----------------|-----------------|------------------|
| Mars   | S1     | Earth:localhost         | 16001                   | Earth:localhost | 6001           | promoted        | running          | Mars:remote1            | 22001                   | Mars:remote1   | 12001          | demoted         | running          |
| Earth  | S1     | Earth:localhost         | 16001                   | Earth:localhost | 6001           | promoted        | running          | Mars:remote1            | 22001                   | Mars:remote1   | 12001          | demoted         | running          |

It takes up more room than it should. I'd like to pass my headings as e.g.

['site', 'name', ['primary', 'database_host', 'database_port', 'host', 'port', 'state', 'status'], ['replica', 'database_host', 'database_port', 'host', 'port', 'state', 'status']]

to get:

| site  | name | primary                                                                       | replica                                                                  |
|       |      | database_host   | database_port | host            | port | state    | status  | database_host | database_port | host         | port  | state   | status  |
|-------|------|---------------  |---------------|-----------------|------|----------|---------|---------------|---------------|--------------|-------|---------|---------|
| Mars  | S1   | Earth:localhost | 16001         | Earth:localhost | 6001 | promoted | running | Mars:remote1  | 22001         | Mars:remote1 | 12001 | demoted | running |
| Earth | S1   | Earth:localhost | 16001         | Earth:localhost | 6001 | promoted | running | Mars:remote1  | 22001         | Mars:remote1 | 12001 | demoted | running |