forked from opencurve/curve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.py
43 lines (39 loc) · 1.26 KB
/
common.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
#!/usr/bin/env python
# coding=utf-8
def printTable(heads, records, notes):
seperatorLen = 1
maxLens = {}
for head in heads:
maxLens[head] = len(str(head))
for record in records:
for head in heads:
word = str(record[head])
if notes and notes.has_key(head) and notes[head].has_key(word):
word = notes[head][word]
if len(word) > maxLens[head]:
maxLens[head] = len(word)
headline = ''
for head in heads:
word = str(head)
while len(word) < maxLens[head] + seperatorLen:
word = ' ' + word
headline = headline + word
linelen = len(headline)
breakline = ''
while len(breakline) < linelen:
breakline = breakline + '-'
print breakline
print headline
print breakline
for record in records:
recordline = ''
for head in heads:
word = str(record[head])
if notes and notes.has_key(head) and notes[head].has_key(word):
word = notes[head][word]
while len(word) < maxLens[head] + seperatorLen:
word = ' ' + word
recordline = recordline + word
print recordline
print breakline
print "Total: %d" % len(records)