python-tabulate
python-tabulate copied to clipboard
[bug] Error if trying to render a table with no rows using maxcolwidths
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"))
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