Format a line of a table. Arguments: headers: A list of strings that are used as the table headers. fields: A list of the same length as `headers` where `fields[i]` is the entry for `headers[i]` in this row. Elements can be of arbitrary types. Pass `headers` to print
(headers, fields)
| 87 | |
| 88 | |
| 89 | def _format_line(headers, fields): |
| 90 | """Format a line of a table. |
| 91 | |
| 92 | Arguments: |
| 93 | headers: A list of strings that are used as the table headers. |
| 94 | fields: A list of the same length as `headers` where `fields[i]` is |
| 95 | the entry for `headers[i]` in this row. Elements can be of |
| 96 | arbitrary types. Pass `headers` to print the header row. |
| 97 | |
| 98 | Returns: |
| 99 | A pretty string. |
| 100 | """ |
| 101 | assert len(fields) == len(headers), (fields, headers) |
| 102 | fields = [ |
| 103 | "%2.4f" % field if isinstance(field, float) else str(field) |
| 104 | for field in fields |
| 105 | ] |
| 106 | return " ".join( |
| 107 | " " * max(0, len(header) - len(field)) + field |
| 108 | for (header, field) in zip(headers, fields) |
| 109 | ) |
| 110 | |
| 111 | |
| 112 | def main(unused_argv): |