X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=bindings%2Fpython%2Fexamples%2Foutput_format_modules%2Fpprint_table.py;fp=bindings%2Fpython%2Fexamples%2Foutput_format_modules%2Fpprint_table.py;h=0000000000000000000000000000000000000000;hp=a7e8255782f78f325580f74816db390a91e26800;hb=300b4c33ef6d346c4251d0421300df2f8bf11ea3;hpb=9872e818aa1a1d9fcf3221db817b70c109248914 diff --git a/bindings/python/examples/output_format_modules/pprint_table.py b/bindings/python/examples/output_format_modules/pprint_table.py deleted file mode 100644 index a7e82557..00000000 --- a/bindings/python/examples/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