Formats an ascii table for given columns and rows. Parameters ---------- columns : list The column names rows : list of tuples The rows in the table. Each tuple must be the same length as ``columns``.
(columns, rows)
| 1174 | |
| 1175 | |
| 1176 | def asciitable(columns, rows): |
| 1177 | """Formats an ascii table for given columns and rows. |
| 1178 | |
| 1179 | Parameters |
| 1180 | ---------- |
| 1181 | columns : list |
| 1182 | The column names |
| 1183 | rows : list of tuples |
| 1184 | The rows in the table. Each tuple must be the same length as |
| 1185 | ``columns``. |
| 1186 | """ |
| 1187 | rows = [tuple(str(i) for i in r) for r in rows] |
| 1188 | columns = tuple(str(i) for i in columns) |
| 1189 | widths = tuple(max(*map(len, x), len(c)) for x, c in zip(zip(*rows), columns)) |
| 1190 | row_template = ("|" + (" %%-%ds |" * len(columns))) % widths |
| 1191 | header = row_template % tuple(columns) |
| 1192 | bar = "+{}+".format("+".join("-" * (w + 2) for w in widths)) |
| 1193 | data = "\n".join(row_template % r for r in rows) |
| 1194 | return "\n".join([bar, header, bar, data, bar]) |
| 1195 | |
| 1196 | |
| 1197 | def put_lines(buf, lines): |
searching dependent graphs…