-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileManager.py
53 lines (44 loc) · 953 Bytes
/
fileManager.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
def parseTable(path):
file = open(path, "r")
rows = list()
keys = list()
index = 0
for row in file:
if index == 1:
index += 1
continue
rowArr = row.split("|")
for i in range(len(rowArr)):
rowArr[i] = rowArr[i].strip()
try:
rowArr[i] = float(rowArr[i])
except ValueError as e:
pass
del rowArr[-1]
if index == 0:
for i in range(len(rowArr)):
rowArr[i] = rowArr[i].lower()
keys = rowArr
else:
row = {}
for i in range(len(rowArr)):
row[keys[i]] = rowArr[i]
rows.append(row)
index += 1
return rows
def formatTable(rows, sizes):
lines = list()
for row in rows:
line = ""
for i in range(len(row)):
if i != 0:
line += " "
cell = str(row[i])
if len(cell) > sizes[i]:
cell = cell[:sizes[i]]
line += cell
for j in range(len(cell), sizes[i]):
line += " "
line += " |"
lines.append(line)
return lines