@@ -6,115 +6,119 @@ Convert lists to ASCII tables
6
6
7
7
.. code :: py
8
8
9
- from table2ascii import table2ascii
10
-
11
- output = table2ascii(
12
- header = [" #" , " G" , " H" , " R" , " S" ],
13
- body = [[" 1" , " 30" , " 40" , " 35" , " 30" ], [" 2" , " 30" , " 40" , " 35" , " 30" ]],
14
- footer = [" SUM" , " 130" , " 140" , " 135" , " 130" ],
15
- )
16
-
17
- print (output)
18
-
19
- """
20
- ╔═════════════════════════════╗
21
- ║ # G H R S ║
22
- ╟─────────────────────────────╢
23
- ║ 1 30 40 35 30 ║
24
- ║ 2 30 40 35 30 ║
25
- ╟─────────────────────────────╢
26
- ║ SUM 130 140 135 130 ║
27
- ╚═════════════════════════════╝
28
- """
9
+ from table2ascii import table2ascii
10
+
11
+ output = table2ascii(
12
+ header = [" #" , " G" , " H" , " R" , " S" ],
13
+ body = [[" 1" , " 30" , " 40" , " 35" , " 30" ], [" 2" , " 30" , " 40" , " 35" , " 30" ]],
14
+ footer = [" SUM" , " 130" , " 140" , " 135" , " 130" ],
15
+ )
16
+
17
+ print (output)
18
+
19
+ """
20
+ ╔═════════════════════════════╗
21
+ ║ # G H R S ║
22
+ ╟─────────────────────────────╢
23
+ ║ 1 30 40 35 30 ║
24
+ ║ 2 30 40 35 30 ║
25
+ ╟─────────────────────────────╢
26
+ ║ SUM 130 140 135 130 ║
27
+ ╚═════════════════════════════╝
28
+ """
29
29
30
30
Set first or last column headings
31
31
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32
32
33
33
.. code :: py
34
34
35
- from table2ascii import table2ascii
35
+ from table2ascii import table2ascii
36
36
37
- output = table2ascii(
38
- body = [[" Assignment" , " 30" , " 40" , " 35" , " 30" ], [" Bonus" , " 10" , " 20" , " 5" , " 10" ]],
39
- first_col_heading = True ,
40
- )
37
+ output = table2ascii(
38
+ body = [[" Assignment" , " 30" , " 40" , " 35" , " 30" ], [" Bonus" , " 10" , " 20" , " 5" , " 10" ]],
39
+ first_col_heading = True ,
40
+ )
41
41
42
- print (output)
42
+ print (output)
43
43
44
- """
45
- ╔════════════╦═══════════════════╗
46
- ║ Assignment ║ 30 40 35 30 ║
47
- ║ Bonus ║ 10 20 5 10 ║
48
- ╚════════════╩═══════════════════╝
49
- """
44
+ """
45
+ ╔════════════╦═══════════════════╗
46
+ ║ Assignment ║ 30 40 35 30 ║
47
+ ║ Bonus ║ 10 20 5 10 ║
48
+ ╚════════════╩═══════════════════╝
49
+ """
50
50
51
51
Set column widths and alignments
52
52
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
53
53
54
54
.. code :: py
55
55
56
- from table2ascii import table2ascii, Alignment
56
+ from table2ascii import table2ascii, Alignment
57
57
58
- output = table2ascii(
59
- header = [" #" , " G" , " H" , " R" , " S" ],
60
- body = [[" 1" , " 30" , " 40" , " 35" , " 30" ], [" 2" , " 30" , " 40" , " 35" , " 30" ]],
61
- first_col_heading = True ,
62
- column_widths = [5 , 5 , 5 , 5 , 5 ],
63
- alignments = [Alignment.LEFT ] + [Alignment.RIGHT ] * 4 ,
64
- )
58
+ output = table2ascii(
59
+ header = [" Product" , " Category" , " Price" , " Rating" ],
60
+ body = [
61
+ [" Milk" , " Dairy" , " $2.99" , " 6.283" ],
62
+ [" Cheese" , " Dairy" , " $10.99" , " 8.2" ],
63
+ [" Apples" , " Produce" , " $0.99" , " 10.00" ],
64
+ ],
65
+ column_widths = [12 , 12 , 12 , 12 ],
66
+ alignments = [Alignment.LEFT , Alignment.CENTER , Alignment.RIGHT , Alignment.DECIMAL ],
67
+ )
65
68
66
- print (output)
69
+ print (output)
67
70
68
- """
69
- ╔═════╦═══════════════════════╗
70
- ║ # ║ G H R S ║
71
- ╟─────╫───────────────────────╢
72
- ║ 1 ║ 30 40 35 30 ║
73
- ║ 2 ║ 30 40 35 30 ║
74
- ╚═════╩═══════════════════════╝
75
- """
71
+ """
72
+ ╔═══════════════════════════════════════════════════╗
73
+ ║ Product Category Price Rating ║
74
+ ╟───────────────────────────────────────────────────╢
75
+ ║ Milk Dairy $2.99 6.283 ║
76
+ ║ Cheese Dairy $10.99 8.2 ║
77
+ ║ Apples Produce $0.99 10.00 ║
78
+ ╚═══════════════════════════════════════════════════╝
79
+ """
76
80
77
81
Use a preset style
78
82
~~~~~~~~~~~~~~~~~~
79
83
80
84
.. code :: py
81
85
82
- from table2ascii import table2ascii, Alignment, PresetStyle
83
-
84
- output = table2ascii(
85
- header = [" First" , " Second" , " Third" , " Fourth" ],
86
- body = [[" 10" , " 30" , " 40" , " 35" ], [" 20" , " 10" , " 20" , " 5" ]],
87
- column_widths = [10 , 10 , 10 , 10 ],
88
- style = PresetStyle.ascii_box
89
- )
90
-
91
- print (output)
92
-
93
- """
94
- +----------+----------+----------+----------+
95
- | First | Second | Third | Fourth |
96
- +----------+----------+----------+----------+
97
- | 10 | 30 | 40 | 35 |
98
- +----------+----------+----------+----------+
99
- | 20 | 10 | 20 | 5 |
100
- +----------+----------+----------+----------+
101
- """
102
-
103
- output = table2ascii(
104
- header = [" First" , " Second" , " Third" , " Fourth" ],
105
- body = [[" 10" , " 30" , " 40" , " 35" ], [" 20" , " 10" , " 20" , " 5" ]],
106
- style = PresetStyle.plain,
107
- cell_padding = 0 ,
108
- alignments = [Alignment.LEFT ] * 4 ,
109
- )
110
-
111
- print (output)
112
-
113
- """
114
- First Second Third Fourth
115
- 10 30 40 35
116
- 20 10 20 5
117
- """
86
+ from table2ascii import table2ascii, Alignment, PresetStyle
87
+
88
+ output = table2ascii(
89
+ header = [" First" , " Second" , " Third" , " Fourth" ],
90
+ body = [[" 10" , " 30" , " 40" , " 35" ], [" 20" , " 10" , " 20" , " 5" ]],
91
+ column_widths = [10 , 10 , 10 , 10 ],
92
+ style = PresetStyle.ascii_box
93
+ )
94
+
95
+ print (output)
96
+
97
+ """
98
+ +----------+----------+----------+----------+
99
+ | First | Second | Third | Fourth |
100
+ +----------+----------+----------+----------+
101
+ | 10 | 30 | 40 | 35 |
102
+ +----------+----------+----------+----------+
103
+ | 20 | 10 | 20 | 5 |
104
+ +----------+----------+----------+----------+
105
+ """
106
+
107
+ output = table2ascii(
108
+ header = [" First" , " Second" , " Third" , " Fourth" ],
109
+ body = [[" 10" , " 30" , " 40" , " 35" ], [" 20" , " 10" , " 20" , " 5" ]],
110
+ style = PresetStyle.plain,
111
+ cell_padding = 0 ,
112
+ alignments = [Alignment.LEFT ] * 4 ,
113
+ )
114
+
115
+ print (output)
116
+
117
+ """
118
+ First Second Third Fourth
119
+ 10 30 40 35
120
+ 20 10 20 5
121
+ """
118
122
119
123
Define a custom style
120
124
~~~~~~~~~~~~~~~~~~~~~
@@ -123,27 +127,27 @@ Check :ref:`TableStyle` for more info.
123
127
124
128
.. code :: py
125
129
126
- from table2ascii import table2ascii, TableStyle
130
+ from table2ascii import table2ascii, TableStyle
127
131
128
- my_style = TableStyle.from_string(" *-..*||:+-+:+ *''*" )
132
+ my_style = TableStyle.from_string(" *-..*||:+-+:+ *''*" )
129
133
130
- output = table2ascii(
131
- header = [" First" , " Second" , " Third" ],
132
- body = [[" 10" , " 30" , " 40" ], [" 20" , " 10" , " 20" ], [" 30" , " 20" , " 30" ]],
133
- style = my_style,
134
- )
134
+ output = table2ascii(
135
+ header = [" First" , " Second" , " Third" ],
136
+ body = [[" 10" , " 30" , " 40" ], [" 20" , " 10" , " 20" ], [" 30" , " 20" , " 30" ]],
137
+ style = my_style,
138
+ )
135
139
136
- print (output)
140
+ print (output)
137
141
138
- """
139
- *-------.--------.-------*
140
- | First : Second : Third |
141
- +-------:--------:-------+
142
- | 10 : 30 : 40 |
143
- | 20 : 10 : 20 |
144
- | 30 : 20 : 30 |
145
- *-------'--------'-------*
146
- """
142
+ """
143
+ *-------.--------.-------*
144
+ | First : Second : Third |
145
+ +-------:--------:-------+
146
+ | 10 : 30 : 40 |
147
+ | 20 : 10 : 20 |
148
+ | 30 : 20 : 30 |
149
+ *-------'--------'-------*
150
+ """
147
151
148
152
Merge adjacent cells
149
153
~~~~~~~~~~~~~~~~~~~~
0 commit comments