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

Add Argument for setting PRESERVE_WHITESPACE to True or False to tabulate #298

Open fdoandres1998 opened 9 months ago

fdoandres1998 commented 9 months ago

The option to whether or not to preserve leading/trailing whitespace in data is hardcoded to False by default. I would like the option to preserve the whitespace when making a table using the tabulate function.

line 72 of tabulate.py

Thanks!

copart commented 3 months ago

When I need to preserve whitespace, I just set the flag you found:

import tabulate
tabulate.PRESERVE_WHITESPACE = True
table = [["Earth", 6371],
         ["  Mars", 3390],
         ["Moon", 1737]]
print(tabulate.tabulate(table, tablefmt="simple"))