tabulate fails on empty data with `headers` and `colalign`
See original GitHub issueIt’s possible to pass an empty tabular_data
value to tabulate
along with headers
and this works as expected:
>>> import tabulate
>>> print(tabulate.tabulate([], headers=['foo', 'bar']))
foo bar
----- -----
>>>
However, if colalign
values are provided as well, it causes an exception:
>>> print(tabulate.tabulate([], headers=['foo', 'bar'], colalign=('left', 'right')))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/ssd/debian-next/venv/lib/python3.8/site-packages/tabulate.py", line 1494, in tabulate
aligns[idx] = align
IndexError: list assignment index out of range
>>>
My expectation is that this would behave as if colalign
wasn’t passed since there’s no data to align.
I encountered this using tabulate 0.8.7.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
tabulate fails on empty data with `headers` and `colalign`
Pretty-print tabular data in Python, a library and a command-line utility. Repository migrated from bitbucket.org/astanin/python-tabulate. See More. Top ...
Read more >Issues · astanin/python-tabulate - GitHub
Pretty-print tabular data in Python, a library and a command-line utility. ... tabulate on empty table omits headers for certain output formats.
Read more >Incorrect column alignment when printing table in Python ...
One possible solution is to rely on some package that has been designed for this purpose, like tabulate: Read more about it!
Read more >Empty rows raises IndexError with colalign - Bitbucket
A B --- --- foo bar baz qux Traceback (most recent call last): File "test.py", line 11, in...
Read more >tabulate · PyPI
Pretty-print tabular data in Python, a library and a command-line utility. The main use cases of the library are: printing small tables without...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for implementing this! I’ll try it out when I get a chance.
@alexwlchan answered to @AlexanderStein already. Regarding @Fifty-Nine’s problem, it is fixed in #221 using directly
headersalign
: