forked from dabeaz-course/practical-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtableformat.py
More file actions
31 lines (29 loc) · 814 Bytes
/
tableformat.py
File metadata and controls
31 lines (29 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# tableformat.py
'''
class which does nothign and provides template is known as abstract class (also in c++)
'''
class TableFormatter: # is an abstract class
def headings(self, headers):
'''
Emit the table headings.
'''
raise NotImplementedError()
def row(self, rowdata):
'''
Emit a single row of table data.
'''
raise NotImplementedError()
class TextTableFormatter(TableFormatter):
'''
Emit a table in text fromat
'''
def headings(self, headers):
for h in headers:
print(f'{h:>10s}', end= ' ')
print()
print(('-'*10 + ' ')*len(headers))
#return super().headings(headers)
def row(self,rowdata):
for d in rowdata:
print(f'{d:>10s}', end= ' ')
print()