Skip to content

Commit

Permalink
Add "none" tablefmt which doesn't do any formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
elric1 committed Mar 3, 2024
1 parent 95ae5eb commit 243899f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tabulate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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("+", "=", "+", "+"),
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 243899f

Please sign in to comment.