Skip to content

Commit 243899f

Browse files
committed
Add "none" tablefmt which doesn't do any formatting
1 parent 95ae5eb commit 243899f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tabulate/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ def _is_file(f):
102102
)
103103

104104

105+
def _none_row(cell_values, colwidths, colaligns):
106+
return " ".join(filter(len, map(lambda x: x.strip(), cell_values)))
107+
105108
def _is_separating_line(row):
106109
row_type = type(row)
107110
is_sl = (row_type == list or row_type == str) and (
@@ -330,6 +333,16 @@ def escape_empty(val):
330333
padding=0,
331334
with_header_hide=None,
332335
),
336+
"none": TableFormat(
337+
lineabove=None,
338+
linebelowheader=None,
339+
linebetweenrows=None,
340+
linebelow=None,
341+
headerrow=_none_row,
342+
datarow=_none_row,
343+
padding=0,
344+
with_header_hide=None,
345+
),
333346
"grid": TableFormat(
334347
lineabove=Line("+", "-", "+", "+"),
335348
linebelowheader=Line("+", "=", "+", "+"),
@@ -1724,6 +1737,14 @@ def tabulate(
17241737
eggs 451
17251738
---- --------
17261739
1740+
"none" applies no formatting and outputs each column stripped of
1741+
leading and trailing whitespace only putting whitespace between
1742+
non-empty columns.
1743+
1744+
>>> print(tabulate([["spam", " ", 41.9999], ["eggs", "a", "451.0"]], tablefmt="none"))
1745+
spam 41.9999
1746+
eggs a 451
1747+
17271748
"grid" is similar to tables produced by Emacs table.el package or
17281749
Pandoc grid_tables:
17291750

0 commit comments

Comments
 (0)