# tableformat.py class TableFormatter: def headings(self, headers): ''' Emit the table headers ''' raise NotImplementedError() def row(self, rowdata): ''' Emit a single row of table data ''' raise NotImplementedError() class TextTableFormatter(TableFormatter): ''' Output data in plain-text format. ''' def headings(self, headers): for h in headers: print(f'{h:>10s}', end=' ') print() print(('-'*10 + ' ')*len(headers)) def row(self, rowdata): for d in rowdata: print(f'{d:>10s}', end=' ') print() class CSVTableFormatter(TableFormatter): ''' Output data in CSV format. ''' def headings(self, headers): print(','.join(headers)) def row(self, rowdata): print(','.join(rowdata)) class HTMLTableFormatter(TableFormatter): ''' Output data in HTML format. ''' def headings(self, headers): print('