Skip to content

Commit 5e2ee10

Browse files
s-cellesastanin
authored andcommitted
Merged in scls19fr/python-tabulate/scls19fr/print-as-a-function-1509553366705 (pull request astanin#45)
Update README examples: use print as a function print as a function
2 parents 518c86a + b89f0ab commit 5e2ee10

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

README.rst

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ and outputs a nicely formatted plain-text table::
6565

6666
>>> table = [["Sun",696000,1989100000],["Earth",6371,5973.6],
6767
... ["Moon",1737,73.5],["Mars",3390,641.85]]
68-
>>> print tabulate(table)
68+
>>> print(tabulate(table))
6969
----- ------ -------------
7070
Sun 696000 1.9891e+09
7171
Earth 6371 5973.6
@@ -91,7 +91,7 @@ Headers
9191
The second optional argument named ``headers`` defines a list of
9292
column headers to be used::
9393

94-
>>> print tabulate(table, headers=["Planet","R (km)", "mass (x 10^29 kg)"])
94+
>>> print(tabulate(table, headers=["Planet","R (km)", "mass (x 10^29 kg)"]))
9595
Planet R (km) mass (x 10^29 kg)
9696
-------- -------- -------------------
9797
Sun 696000 1.9891e+09
@@ -101,8 +101,8 @@ column headers to be used::
101101

102102
If ``headers="firstrow"``, then the first row of data is used::
103103

104-
>>> print tabulate([["Name","Age"],["Alice",24],["Bob",19]],
105-
... headers="firstrow")
104+
>>> print(tabulate([["Name","Age"],["Alice",24],["Bob",19]],
105+
... headers="firstrow"))
106106
Name Age
107107
------ -----
108108
Alice 24
@@ -113,8 +113,8 @@ If ``headers="keys"``, then the keys of a dictionary/dataframe, or
113113
column indices are used. It also works for NumPy record arrays and
114114
lists of dictionaries or named tuples::
115115

116-
>>> print tabulate({"Name": ["Alice", "Bob"],
117-
... "Age": [24, 19]}, headers="keys")
116+
>>> print(tabulate({"Name": ["Alice", "Bob"],
117+
... "Age": [24, 19]}, headers="keys"))
118118
Age Name
119119
----- ------
120120
24 Alice
@@ -171,7 +171,7 @@ Supported table formats are:
171171

172172
>>> table = [["spam",42],["eggs",451],["bacon",0]]
173173
>>> headers = ["item", "qty"]
174-
>>> print tabulate(table, headers, tablefmt="plain")
174+
>>> print(tabulate(table, headers, tablefmt="plain"))
175175
item qty
176176
spam 42
177177
eggs 451
@@ -181,7 +181,7 @@ Supported table formats are:
181181
versions). It corresponds to ``simple_tables`` in `Pandoc Markdown
182182
extensions`_::
183183

184-
>>> print tabulate(table, headers, tablefmt="simple")
184+
>>> print(tabulate(table, headers, tablefmt="simple"))
185185
item qty
186186
------ -----
187187
spam 42
@@ -192,7 +192,7 @@ extensions`_::
192192
package. It corresponds to ``grid_tables`` in Pandoc Markdown
193193
extensions::
194194

195-
>>> print tabulate(table, headers, tablefmt="grid")
195+
>>> print(tabulate(table, headers, tablefmt="grid"))
196196
+--------+-------+
197197
| item | qty |
198198
+========+=======+
@@ -205,7 +205,7 @@ extensions::
205205

206206
``fancy_grid`` draws a grid using box-drawing characters::
207207

208-
>>> print tabulate(table, headers, tablefmt="fancy_grid")
208+
>>> print(tabulate(table, headers, tablefmt="fancy_grid"))
209209
╒════════╤═══════╕
210210
│ item │ qty │
211211
╞════════╪═══════╡
@@ -218,7 +218,7 @@ extensions::
218218

219219
``presto`` is like tables formatted by Presto cli::
220220

221-
>>> print tabulate.tabulate()
221+
>>> print(tabulate.tabulate())
222222
item | qty
223223
--------+-------
224224
spam | 42
@@ -227,7 +227,7 @@ extensions::
227227

228228
``psql`` is like tables formatted by Postgres' psql cli::
229229

230-
>>> print tabulate.tabulate()
230+
>>> print(tabulate.tabulate())
231231
+--------+-------+
232232
| item | qty |
233233
|--------+-------|
@@ -240,7 +240,7 @@ extensions::
240240
corresponds to ``pipe_tables`` in Pandoc. This format uses colons to
241241
indicate column alignment::
242242

243-
>>> print tabulate(table, headers, tablefmt="pipe")
243+
>>> print(tabulate(table, headers, tablefmt="pipe"))
244244
| item | qty |
245245
|:-------|------:|
246246
| spam | 42 |
@@ -250,7 +250,7 @@ indicate column alignment::
250250
``orgtbl`` follows the conventions of Emacs `org-mode`_, and is editable
251251
also in the minor `orgtbl-mode`. Hence its name::
252252

253-
>>> print tabulate(table, headers, tablefmt="orgtbl")
253+
>>> print(tabulate(table, headers, tablefmt="orgtbl"))
254254
| item | qty |
255255
|--------+-------|
256256
| spam | 42 |
@@ -259,15 +259,15 @@ also in the minor `orgtbl-mode`. Hence its name::
259259

260260
``jira`` follows the conventions of Atlassian Jira markup language::
261261

262-
>>> print tabulate(table, headers, tablefmt="jira")
262+
>>> print(tabulate(table, headers, tablefmt="jira"))
263263
|| item || qty ||
264264
| spam | 42 |
265265
| eggs | 451 |
266266
| bacon | 0 |
267267

268268
``rst`` formats data like a simple table of the `reStructuredText`_ format::
269269

270-
>>> print tabulate(table, headers, tablefmt="rst")
270+
>>> print(tabulate(table, headers, tablefmt="rst"))
271271
====== =====
272272
item qty
273273
====== =====
@@ -279,7 +279,7 @@ also in the minor `orgtbl-mode`. Hence its name::
279279
``mediawiki`` format produces a table markup used in `Wikipedia`_ and on
280280
other MediaWiki-based sites::
281281

282-
>>> print tabulate(table, headers, tablefmt="mediawiki")
282+
>>> print(tabulate(table, headers, tablefmt="mediawiki"))
283283
{| class="wikitable" style="text-align: left;"
284284
|+ <!-- caption -->
285285
|-
@@ -295,7 +295,7 @@ other MediaWiki-based sites::
295295
``moinmoin`` format produces a table markup used in `MoinMoin`_
296296
wikis::
297297

298-
>>> print tabulate(d,headers,tablefmt="moinmoin")
298+
>>> print(tabulate(d,headers,tablefmt="moinmoin"))
299299
|| ''' item ''' || ''' quantity ''' ||
300300
|| spam || 41.999 ||
301301
|| eggs || 451 ||
@@ -304,23 +304,23 @@ wikis::
304304
``youtrack`` format produces a table markup used in Youtrack
305305
tickets::
306306

307-
>>> print tabulate(d,headers,tablefmt="youtrack")
307+
>>> print(tabulate(d,headers,tablefmt="youtrack"))
308308
|| item || quantity ||
309309
| spam | 41.999 |
310310
| eggs | 451 |
311311
| bacon | |
312312

313313
``textile`` format produces a table markup used in `Textile`_ format::
314314

315-
>>> print tabulate(table, headers, tablefmt='textile')
315+
>>> print(tabulate(table, headers, tablefmt='textile'))
316316
|_. item |_. qty |
317317
|<. spam |>. 42 |
318318
|<. eggs |>. 451 |
319319
|<. bacon |>. 0 |
320320

321321
``html`` produces standard HTML markup::
322322

323-
>>> print tabulate(table, headers, tablefmt="html")
323+
>>> print(tabulate(table, headers, tablefmt="html"))
324324
<table>
325325
<tbody>
326326
<tr><th>item </th><th style="text-align: right;"> qty</th></tr>
@@ -334,7 +334,7 @@ tickets::
334334
replacing special characters like ``_`` or ``\`` to their LaTeX
335335
correspondents::
336336

337-
>>> print tabulate(table, headers, tablefmt="latex")
337+
>>> print(tabulate(table, headers, tablefmt="latex"))
338338
\begin{tabular}{lr}
339339
\hline
340340
item & qty \\
@@ -378,7 +378,7 @@ You can override the default alignment with ``numalign`` and
378378
Aligning by a decimal point works best when you need to compare
379379
numbers at a glance::
380380

381-
>>> print tabulate([[1.2345],[123.45],[12.345],[12345],[1234.5]])
381+
>>> print(tabulate([[1.2345],[123.45],[12.345],[12345],[1234.5]]))
382382
----------
383383
1.2345
384384
123.45
@@ -389,7 +389,7 @@ numbers at a glance::
389389

390390
Compare this with a more common right alignment::
391391

392-
>>> print tabulate([[1.2345],[123.45],[12.345],[12345],[1234.5]], numalign="right")
392+
>>> print(tabulate([[1.2345],[123.45],[12.345],[12345],[1234.5]], numalign="right"))
393393
------
394394
1.2345
395395
123.45
@@ -409,7 +409,7 @@ from a file:
409409
>>> table = list(csv.reader(StringIO("spam, 42\neggs, 451\n")))
410410
>>> table
411411
[['spam', ' 42'], ['eggs', ' 451']]
412-
>>> print tabulate(table)
412+
>>> print(tabulate(table))
413413
---- ----
414414
spam 42
415415
eggs 451
@@ -423,7 +423,7 @@ Number formatting
423423
``tabulate`` allows to define custom number formatting applied to all
424424
columns of decimal numbers. Use ``floatfmt`` named argument::
425425

426-
>>> print tabulate([["pi",3.141593],["e",2.718282]], floatfmt=".4f")
426+
>>> print(tabulate([["pi",3.141593],["e",2.718282]], floatfmt=".4f"))
427427
-- ------
428428
pi 3.1416
429429
e 2.7183
@@ -432,7 +432,7 @@ columns of decimal numbers. Use ``floatfmt`` named argument::
432432
``floatfmt`` argument can be a list or a tuple of format strings,
433433
one per column, in which case every column may have different number formatting::
434434

435-
>>> print tabulate([[0.12345, 0.12345, 0.12345]], floatfmt=(".1f", ".3f"))
435+
>>> print(tabulate([[0.12345, 0.12345, 0.12345]], floatfmt=(".1f", ".3f")))
436436
--- ----- -------
437437
0.1 0.123 0.12345
438438
--- ----- -------

0 commit comments

Comments
 (0)