From 243899f07a9027a53e816d0f3f2b600ddd30ffe4 Mon Sep 17 00:00:00 2001 From: "Roland C. Dowdeswell" Date: Sun, 3 Mar 2024 22:10:16 +0000 Subject: [PATCH] Add "none" tablefmt which doesn't do any formatting --- tabulate/__init__.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tabulate/__init__.py b/tabulate/__init__.py index 11bb865..b5968c4 100644 --- a/tabulate/__init__.py +++ b/tabulate/__init__.py @@ -102,6 +102,9 @@ def _is_file(f): ) +def _none_row(cell_values, colwidths, colaligns): + return " ".join(filter(len, map(lambda x: x.strip(), cell_values))) + def _is_separating_line(row): row_type = type(row) is_sl = (row_type == list or row_type == str) and ( @@ -330,6 +333,16 @@ def escape_empty(val): padding=0, with_header_hide=None, ), + "none": TableFormat( + lineabove=None, + linebelowheader=None, + linebetweenrows=None, + linebelow=None, + headerrow=_none_row, + datarow=_none_row, + padding=0, + with_header_hide=None, + ), "grid": TableFormat( lineabove=Line("+", "-", "+", "+"), linebelowheader=Line("+", "=", "+", "+"), @@ -1724,6 +1737,14 @@ def tabulate( eggs 451 ---- -------- + "none" applies no formatting and outputs each column stripped of + leading and trailing whitespace only putting whitespace between + non-empty columns. + + >>> print(tabulate([["spam", " ", 41.9999], ["eggs", "a", "451.0"]], tablefmt="none")) + spam 41.9999 + eggs a 451 + "grid" is similar to tables produced by Emacs table.el package or Pandoc grid_tables: