(records, fields, formatter)
| 2 | from abc import ABC, abstractmethod |
| 3 | |
| 4 | def print_table(records, fields, formatter): |
| 5 | if not isinstance(formatter, TableFormatter): |
| 6 | raise RuntimeError('Expected a TableFormatter') |
| 7 | |
| 8 | formatter.headings(fields) |
| 9 | for r in records: |
| 10 | rowdata = [getattr(r, fieldname) for fieldname in fields] |
| 11 | formatter.row(rowdata) |
| 12 | |
| 13 | class TableFormatter(ABC): |
| 14 | @abstractmethod |