forked from aliev/runestone
-
Notifications
You must be signed in to change notification settings - Fork 3
/
toRstTable.py
executable file
·50 lines (37 loc) · 951 Bytes
/
toRstTable.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
#!/usr/local/bin/python3.2
__author__ = 'bmiller'
import sys
oldTable = sys.stdin.readlines()
numCols = oldTable.count('&')
i = 0
while i < len(oldTable):
oldTable[i] = oldTable[i].split('&')
i += 1
numCols = len(oldTable[0])
colMax = [0 for x in range(numCols)]
for col in range(numCols):
for row in range(len(oldTable)):
if len(oldTable[row]) == numCols:
if len(oldTable[row][col].strip()) > colMax[col]:
colMax[col] = len(oldTable[row][col])
# print header info
for c in colMax:
print("="*c,end=' ')
print()
col = 0
for h in oldTable[0]:
print(("%"+str(colMax[col])+"s") % h.strip(),end=' ')
col += 1
print()
for c in colMax:
print("="*c,end=' ')
print()
for row in range(1,len(oldTable)):
col = 0
for h in oldTable[row]:
print(("%"+str(colMax[col])+"s") % h.strip(),end=' ')
col += 1
print()
for c in colMax:
print("="*c,end=' ')
print()