python-tabulate icon indicating copy to clipboard operation
python-tabulate copied to clipboard

[bug] Error if trying to render a table with no rows using maxcolwidths

Open elehcimd opened this issue 1 year ago • 1 comments

With tabulate==0.9.0

This code fails:

print(tabulate({'x': []}, headers="keys", maxcolwidths=100))

Expected behaviour:

Without data, it should render the table as with:

print(tabulate({'x': []}, headers="keys"))

elehcimd avatar Mar 04 '24 09:03 elehcimd

You can quickly fix this by editing this line: https://github.com/astanin/python-tabulate/blob/95ae5eb61ef969749e904c90ab429003238d6212/tabulate/init.py#L2109

Into

        num_cols = len(list_of_lists[0]) if list_of_lists else 0

devdanzin avatar Mar 04 '24 10:03 devdanzin