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

feature: Limit the width of my table based on the width of the console #290

Open Adamou02 opened 11 months ago

Adamou02 commented 11 months ago

Description

Error occurs when I print a table larger than my console output.

image

Problem, I do not know in advance the number of columns in my tabulate table

Expected behavior

Actually, I have this line :

print(tabulate(data_results, headers="keys", tablefmt="fancy_grid", maxcolwidths=30, showindex=False))

I would like to replace the maxcolwidths=30 with maxcolwidths='automatic'.

This flag will adapt the size of the columns according to the formula console width / number of columns

frank-lenormand commented 11 months ago

I’m experiencing the same issue, and I believe this to be a bug.

The engine allows columns to be rendered with a width greater than the value of maxcolwidths, when their contents do not exceed that limit.

For example, an empty cell, or one that doesn’t have contents exceeding maxcolwidths codepoints.