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

Add Argument for setting PRESERVE_WHITESPACE to True or False to tabulate

Open fdoandres1998 opened this issue 2 years ago • 1 comments

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!

fdoandres1998 avatar Nov 06 '23 17:11 fdoandres1998

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"))

copart avatar Apr 26 '24 02:04 copart