Skip to content

Commit fca646f

Browse files
committed
working HTMLTableFormatter
1 parent 15922b4 commit fca646f

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

‎Work/report.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def portfolio_report(portfoliofile, pricefile):
5757
report = make_report_data(portfolio, prices)
5858

5959
# Print it out
60-
formatter = tableformat.TextTableFormatter()
60+
formatter = tableformat.HTMLTableFormatter()
6161
print_report(report, formatter)
6262

6363
def main(args):

‎Work/tableformat.py‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,23 @@ def headings(self, headers):
3131
print(','.join(headers))
3232

3333
def row(self, rowdata):
34-
print(','.join(rowdata))
34+
print(','.join(rowdata))
35+
36+
class HTMLTableFormatter(TableFormatter):
37+
38+
def headings(self, headings):
39+
begingHTML = '<tr>'
40+
endHTML = '</tr>'
41+
for h in headings:
42+
begingHTML += f'<th>{h}</th>'
43+
begingHTML += endHTML
44+
print(begingHTML)
45+
46+
def row(self, rowdata):
47+
starttd = '<tr>'
48+
endtd = '</tr>'
49+
for d in rowdata:
50+
starttd += f'<td>{d}</td>'
51+
starttd += endtd
52+
print(starttd)
53+

0 commit comments

Comments
 (0)