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.08k stars 162 forks source link

stralign=None breaks table completely #294

Open AntonOvsyannikov opened 10 months ago

AntonOvsyannikov commented 10 months ago

I need to print table with leading spaces in some rows data (like execution plan from postgres), the only way I found is to use stralign=None , but it breaks the table completely for most formats

from tabulate import tabulate

print(tabulate([["    foo"], ["bar"]], stralign=None, tablefmt="pretty"))
+---------+
|     foo |
| bar |
+---------+

Workaround-like is to use default stralign and replace leading spaces with something printable (any non-visible chars are stripped), so actually there is no workaround.

EXPLAIN SELECT 1 UNION SELECT 2

╭────────────────────────────────────────────────────────────╮
│ QUERY PLAN                                                 │
├────────────────────────────────────────────────────────────┤
│ Unique  (cost=0.11..0.12 rows=2 width=4)                   │
│ ``->  Sort  (cost=0.11..0.12 rows=2 width=4)               │
│ ````````Sort Key: (1)                                      │
│ ````````->  Append  (cost=0.00..0.05 rows=2 width=4)       │
│ ``````````````->  Result  (cost=0.00..0.01 rows=1 width=4) │
│ ``````````````->  Result  (cost=0.00..0.01 rows=1 width=4) │
╰────────────────────────────────────────────────────────────╯