@@ -6,115 +6,119 @@ Convert lists to ASCII tables
66
77.. code :: py
88
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+ """
2929
3030 Set first or last column headings
3131~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3232
3333.. code :: py
3434
35- from table2ascii import table2ascii
35+ from table2ascii import table2ascii
3636
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+ )
4141
42- print (output)
42+ print (output)
4343
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+ """
5050
5151 Set column widths and alignments
5252~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5353
5454.. code :: py
5555
56- from table2ascii import table2ascii, Alignment
56+ from table2ascii import table2ascii, Alignment
5757
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+ )
6568
66- print (output)
69+ print (output)
6770
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+ """
7680
7781 Use a preset style
7882~~~~~~~~~~~~~~~~~~
7983
8084.. code :: py
8185
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+ """
118122
119123 Define a custom style
120124~~~~~~~~~~~~~~~~~~~~~
@@ -123,27 +127,27 @@ Check :ref:`TableStyle` for more info.
123127
124128.. code :: py
125129
126- from table2ascii import table2ascii, TableStyle
130+ from table2ascii import table2ascii, TableStyle
127131
128- my_style = TableStyle.from_string(" *-..*||:+-+:+ *''*" )
132+ my_style = TableStyle.from_string(" *-..*||:+-+:+ *''*" )
129133
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+ )
135139
136- print (output)
140+ print (output)
137141
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+ """
147151
148152 Merge adjacent cells
149153~~~~~~~~~~~~~~~~~~~~
0 commit comments