Complicated example#
These python commands setup the table:
1import pyRestTable
2t = pyRestTable.Table()
3t.addLabel('Name\nand\nAttributes')
4t.addLabel('Type')
5t.addLabel('Units')
6t.addLabel('Description\n(and Occurrences)')
7t.addRow( ['one,\ntwo', "buckle my", "shoe.\n\n\nthree,\nfour", "..."] )
8t.addRow( ['class', 'NX_FLOAT', '', None, ] )
9t.addRow( range(0,4) )
10t.addRow( [None, {'a': 1, 'b': 'dreamy'}, 1.234, range(3)] )
11t.setLongtable()
12t.setTabularColumns(True, 'l L c r'.split())
Here, we assert more control over the table format using
setLongtable()
and
setTabularColumns()
configuration options.
Format: print(t.reST(fmt=’simple’))#
this reST code:
1.. tabularcolumns:: |l|L|c|r|
2 :longtable:
3
4========== ======================= ====== =================
5Name Type Units Description
6and (and Occurrences)
7Attributes
8========== ======================= ====== =================
9one, buckle my shoe. ...
10two
11
12 three,
13 four
14class NX_FLOAT None
150 1 2 3
16None {'a': 1, 'b': 'dreamy'} 1.234 [0, 1, 2]
17========== ======================= ====== =================
is rendered as:
Name |
Type |
Units |
Description |
---|---|---|---|
and |
(and Occurrences) |
||
Attributes |
|||
one, |
buckle my |
shoe. |
… |
two |
three, four |
||
class |
NX_FLOAT |
None |
|
0 |
1 |
2 |
3 |
None |
{‘a’: 1, ‘b’: ‘dreamy’} |
1.234 |
[0, 1, 2] |
Format: print(t.reST(fmt=’grid’))#
this reST code:
1.. tabularcolumns:: |l|L|c|r|
2 :longtable:
3
4+------------+-------------------------+--------+-------------------+
5| Name | Type | Units | Description |
6| and | | | (and Occurrences) |
7| Attributes | | | |
8+============+=========================+========+===================+
9| one, | buckle my | shoe. | ... |
10| two | | | |
11| | | | |
12| | | three, | |
13| | | four | |
14+------------+-------------------------+--------+-------------------+
15| class | NX_FLOAT | | None |
16+------------+-------------------------+--------+-------------------+
17| 0 | 1 | 2 | 3 |
18+------------+-------------------------+--------+-------------------+
19| None | {'a': 1, 'b': 'dreamy'} | 1.234 | [0, 1, 2] |
20+------------+-------------------------+--------+-------------------+
is rendered as:
Name and Attributes |
Type |
Units |
Description (and Occurrences) |
---|---|---|---|
one, two |
buckle my |
shoe. three, four |
… |
class |
NX_FLOAT |
None |
|
0 |
1 |
2 |
3 |
None |
{‘a’: 1, ‘b’: ‘dreamy’} |
1.234 |
[0, 1, 2] |
Format: print(t.reST(fmt=’list-table’))#
this reST code:
1.. list-table::
2 :header-rows: 1
3 :widths: 10 23 6 17
4
5 * - Name
6 and
7 Attributes
8 - Type
9 - Units
10 - Description
11 (and Occurrences)
12 * - one,
13 two
14 - buckle my
15 - shoe.
16
17
18 three,
19 four
20 - ...
21 * - class
22 - NX_FLOAT
23 -
24 -
25 * - 0
26 - 1
27 - 2
28 - 3
29 * - None
30 - {'a': 1, 'b': 'dreamy'}
31 - 1.234
32 - [0, 1, 2]
is rendered as:
Name and Attributes |
Type |
Units |
Description (and Occurrences) |
---|---|---|---|
one, two |
buckle my |
shoe. three, four |
… |
class |
NX_FLOAT |
||
0 |
1 |
2 |
3 |
None |
{‘a’: 1, ‘b’: ‘dreamy’} |
1.234 |
[0, 1, 2] |