a little nicer wrt pep8
[sfa.git] / sfatables / pretty.py
1 #!/usr/bin/env python3
2
3 class Pretty:
4     rows = []
5     column_width = []
6
7     def __init__(self, header):
8         self.rows.append(header)
9         for c in header:
10             self.column_width.append(len(header))
11
12     def push_row (self, row):
13         self.rows.append(row)
14         num = 0
15         for c in row:
16             if (self.column_width[num] < len(c)):
17                 self.column_width[num] = len(c)
18             num = num + 1
19         return
20
21     def pprint (self):
22         print('\n')
23
24         for rule in self.rows:
25             cur_line = ""
26             num = 0
27
28             for r in rule:
29                 cur_line = cur_line + "%s "%r
30                 if (self.column_width[num] > len(r)):
31                     padding0 = ''.zfill(self.column_width[num] - len(r))
32                     padding = padding0.replace('0',' ')
33                     cur_line = cur_line + padding
34                 num = num + 1
35
36             print(cur_line)
37
38