Skip to content

Commit a352ad5

Browse files
satterlyastanin
authored andcommitted
Merged in satterly/python-tabulate/presto-format (pull request astanin#35)
add presto cli table format
2 parents 75c2603 + 6dc6da4 commit a352ad5

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

README.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ Supported table formats are:
155155
- "pipe"
156156
- "orgtbl"
157157
- "jira"
158+
- "presto"
158159
- "psql"
159160
- "rst"
160161
- "mediawiki"
@@ -215,6 +216,15 @@ extensions::
215216
│ bacon │ 0 │
216217
╘════════╧═══════╛
217218

219+
``presto`` is like tables formatted by Presto cli::
220+
221+
>>> print tabulate.tabulate()
222+
item | qty
223+
--------+-------
224+
spam | 42
225+
eggs | 451
226+
bacon | 0
227+
218228
``psql`` is like tables formatted by Postgres' psql cli::
219229

220230
>>> print tabulate.tabulate()

tabulate.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,14 @@ def escape_empty(val):
271271
headerrow=DataRow("||", "||", "||"),
272272
datarow=DataRow("|", "|", "|"),
273273
padding=1, with_header_hide=None),
274+
"presto":
275+
TableFormat(lineabove=None,
276+
linebelowheader=Line("", "-", "+", ""),
277+
linebetweenrows=None,
278+
linebelow=None,
279+
headerrow=DataRow("", "|", ""),
280+
datarow=DataRow("", "|", ""),
281+
padding=1, with_header_hide=None),
274282
"psql":
275283
TableFormat(lineabove=Line("+", "-", "+", "+"),
276284
linebelowheader=Line("|", "-", "+", "|"),
@@ -1028,6 +1036,15 @@ def tabulate(tabular_data, headers=(), tablefmt="simple",
10281036
| spam | 41.9999 |
10291037
| eggs | 451 |
10301038
1039+
"presto" is like tables produce by the Presto CLI:
1040+
1041+
>>> print(tabulate([["spam", 41.9999], ["eggs", "451.0"]],
1042+
... ["strings", "numbers"], "presto"))
1043+
strings | numbers
1044+
-----------+-----------
1045+
spam | 41.9999
1046+
eggs | 451
1047+
10311048
>>> print(tabulate([["spam", 41.9999], ["eggs", "451.0"]], tablefmt="pipe"))
10321049
|:-----|---------:|
10331050
| spam | 41.9999 |

0 commit comments

Comments
 (0)