a7e8255782f78f325580f74816db390a91e26800
3 # This module is used to pretty-print a table
5 # http://ginstrom.com/scribbles/2007/09/04/pretty-printing-a-table-in-python/
9 def get_max_width(table
, index
):
10 """Get the maximum width of the given column index"""
12 return max([len(str(row
[index
])) for row
in table
])
15 def pprint_table(table
, nbLeft
=1, out
=sys
.stdout
):
17 Prints out a table of data, padded for alignment
18 @param table: The table to print. A list of lists.
19 Each row must have the same number of columns.
20 @param nbLeft: The number of columns aligned left
21 @param out: Output stream (file-like object)
26 for i
in range(len(table
[0])):
27 col_paddings
.append(get_max_width(table
, i
))
31 for i
in range(nbLeft
):
32 print >> out
, str(row
[i
]).ljust(col_paddings
[i
] + 1),
34 for i
in range(nbLeft
, len(row
)):
35 col
= str(row
[i
]).rjust(col_paddings
[i
] + 2)
This page took 0.02914 seconds and 3 git commands to generate.