Package jazzparser :: Package utils :: Module tableprint
[hide private]
[frames] | no frames]

Module tableprint

source code

Pretty-printing tables as strings.

A bit of simple code to output a table to stdout.

Many thanks to http://ginstrom.com/scribbles/2007/09/04/pretty-printing-a-table-in-python/ for the basic code that I used to do the core stuff here. I've developed on it a bit myself and added the Latex table stuff down the bottom.


Author: Mark Granroth-Wilding <mark.granroth-wilding@ed.ac.uk>

Functions [hide private]
 
format_num(num)
Format a number according to given places.
source code
 
get_max_width(table, index)
Get the maximum width of the given column index
source code
 
format_table(*args, **kwargs)
Like pprint_table, but returns a string containing the formatted table, whilst pprint_table outputs directly to a stream.
source code
 
pprint_table(out, table, justs=None, separator=None, outer_seps=False, widths=None, blank_row=False, default_just=None, hanging_indent=0)
Prints out a table of data, padded for alignment.
source code
 
print_latex_table(out, table, justs=None, separator=None, headings=False)
Prints out the Latex code to display the given 2D list as a table.
source code
Variables [hide private]
  __package__ = 'jazzparser.utils'
Function Details [hide private]

format_num(num)

source code 

Format a number according to given places. Adds commas, etc. Will truncate floats into ints!

format_table(*args, **kwargs)

source code 

Like pprint_table, but returns a string containing the formatted table, whilst pprint_table outputs directly to a stream.

Args and kwargs are the same as to pprint_table.

pprint_table(out, table, justs=None, separator=None, outer_seps=False, widths=None, blank_row=False, default_just=None, hanging_indent=0)

source code 

Prints out a table of data, padded for alignment. Each row must have the same number of columns.

Cells may include line breaks.

Parameters:
  • out (file-like object) - output stream
  • table (list of lists) - table to print.
  • outer_seps (bool) - Prints separators at the start and end of each row if true.
  • widths (list of ints) - maximum width for each column. None means no maximum is imposed. Words are wrapped if the width exceeds the maximum
  • default_just (bool) - the default justification to use for all columns if justs is not given or where a column's justification is not given. Default False
  • hanging_indent (int) - hanging indent to apply to the column if a cell is wrapped (number of spaces)