X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=bindings%2Fpython%2Fexamples%2Fpython2%2Foutput_format_modules%2Fpprint_table.py;fp=bindings%2Fpython%2Fexamples%2Fpython2%2Foutput_format_modules%2Fpprint_table.py;h=0000000000000000000000000000000000000000;hp=3a63d628348db4405a4628ade628c836f6217a9a;hb=3043ee0c1760e16f7c3adc7526c4a5339d3d269d;hpb=810a97bebd52f8ae8eb557fde557318b815f32e1 diff --git a/bindings/python/examples/python2/output_format_modules/pprint_table.py b/bindings/python/examples/python2/output_format_modules/pprint_table.py deleted file mode 100644 index 3a63d628..00000000 --- a/bindings/python/examples/python2/output_format_modules/pprint_table.py +++ /dev/null @@ -1,37 +0,0 @@ -# pprint_table.py -# -# This module is used to pretty-print a table -# Adapted from -# http://ginstrom.com/scribbles/2007/09/04/pretty-printing-a-table-in-python/ - -import sys - -def get_max_width(table, index): - """Get the maximum width of the given column index""" - - return max([len(str(row[index])) for row in table]) - - -def pprint_table(table, nbLeft=1, out=sys.stdout): - """ - Prints out a table of data, padded for alignment - @param table: The table to print. A list of lists. - Each row must have the same number of columns. - @param nbLeft: The number of columns aligned left - @param out: Output stream (file-like object) - """ - - col_paddings = [] - - for i in range(len(table[0])): - col_paddings.append(get_max_width(table, i)) - - for row in table: - # left cols - for i in range(nbLeft): - print >> out, str(row[i]).ljust(col_paddings[i] + 1), - # rest of the cols - for i in range(nbLeft, len(row)): - col = str(row[i]).rjust(col_paddings[i] + 2) - print >> out, col, - print >> out