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

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

Open elehcimd opened 5 months ago

elehcimd commented 5 months ago

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"))
devdanzin commented 5 months ago

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