-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtables.py
More file actions
40 lines (32 loc) · 994 Bytes
/
tables.py
File metadata and controls
40 lines (32 loc) · 994 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
32
33
34
35
36
37
38
39
40
from prettytable import PrettyTable
class Table:
def __init__(self, name, headers, rows) -> None:
self.name = name
self.headers = headers
self.rows = rows
self.table = self.create_table()
def create_table(self):
table = PrettyTable()
table.field_names = self.headers
table.align = 'r'
for row in self.rows:
table.add_row(row)
return table
def print(self):
print(self.name + ":")
print(self.table)
def get_string(self):
return self.table.get_string()
class Tables:
def __init__(self, tables=[]) -> None:
self.tables = tables
def append(self, table):
self.tables.append(table)
def print(self):
for table in self.tables:
table.print()
def get_string(self):
result = ""
for table in self.tables:
result += "{}\n{}\n".format(table.name, table.get_string())
return result