easytable

Submodules:

Create table representations from various data structures.

Various data structures are considered: Lists containing lists, dictionaries containing lists, lists containing dictionaries etc. The idea of this package is to find the natural table-like representation for each of the considered data structures.

The function autotable() is provided that can infer an appropiate table form the given data structure. autotable() is the preferred function to generate the table representation of most kind of tables.

autotable() is choosing one of the following specialized functions which is appropiate for the kind of data structure that has been passed to it. The goal is to support of as many data structures as possible. The special functions can also used directly, to force a certain representation:

docl():
dictionary of lists, where each list represents a named column
dorl():
dictionary of lists, where each list represents a named row
locl():
list of lists, where each list represents a column
lorl():
list of lists, where each list represents a row
locd():
list of dictionaries, where each dictionary represents a column
lord():
list of dictionaries, where each dictionary represents a row
docd():
dictionary of dictionaries, where each dictionary represents a named column, and each key in the latter defines the name of the row
dord():
dictionary of dictionaries, where each dictionary represents a named row, and each key in the latter defines the name of the column

For absolute fine control, the Table class can be used directly to construct the table by hand. The method Table.make() offers a lot of options to format the table. For a complete list, refer to the documentation of Table.make(). The respective keyword arguments can also be passed through the shortcut functions autotable(), docl() etc. A few formatting presets can be found in the submodule presets.

At the moment, there are no ambitions to implement any sorting or filtering options. Data structures have to be passed in an already ordered way. Tip: In the case of dictionaries, the class collections.OrderedDict can be used to force a certain row or column order in the table output.

Functions

easytable.autotable(data_structure, **kwargs)[source]

Generate table representation of the given data structure. Choose one of the specialized functions docl, dorl, etc. based on the given data structure. Keyword arguments are passed to Table.make().

easytable.docl(dict_of_lists, **kwargs)[source]

Return table representation of the given dictionary of lists, where each list represents a named column. Keyword arguments are passed to Table.make().

easytable.dorl(dict_of_lists, **kwargs)[source]

Return table representation of the given dictionary of lists, where each list represents a named row. Keyword arguments are passed to Table.make().

easytable.locl(list_of_lists, **kwargs)[source]

Return table representation of the given list of lists, where each list represents a column. Keyword arguments are passed to Table.make().

easytable.lorl(list_of_lists, **kwargs)[source]

Return table representation of the given list of lists, where each list represents a row. Keyword arguments are passed to Table.make().

easytable.locd(list_of_dicts, **kwargs)[source]

Return table representation of the given list of dictionaries, where each dictionary represents a column. Keyword arguments are passed to Table.make().

easytable.lord(list_of_dicts, **kwargs)[source]

Return table representation of the given list of dictionaries, where each dictionary represents a row. Keyword arguments are passed to Table.make().

easytable.docd(dict_of_dicts, **kwargs)[source]

Return table representation of the given dictionary of dictionaries, where each dictionary represents a column. Keyword arguments are passed to Table.make().

easytable.dord(dict_of_dicts, **kwargs)[source]

Return table representation of the given dictionary of dictionaries, where each dictionary represents a row. Keyword arguments are passed to Table.make().

Auxiliary functions

easytable.isiter(obj)[source]

Check if an object is iterable. Return True for lists, tuples, dictionaries and numpy arrays (all objects that possess an __iter__ method). Return False for scalars (float, int, etc.), strings, bool and None.

easytable.alliter(seq)[source]
easytable.isdict(obj)[source]

Check if the given object obj is a dictionary.

easytable.alldict(seq)[source]
easytable.all_of_type(seq, dtype)[source]

Check if all items of the given sequence seq are of the type dtype. dtype can also be a list of possible types.

Classes

class easytable.Table(cells=None, rowtitles=None, coltitles=None, colalign=None)[source]
append_column(data, title=None, align=None, startrow=0)[source]
append_row(data, title=None, startcol=0)[source]
bottom()[source]
cells[source]
colalign[source]
colinds()[source]
colstrings(index, withtitle=False, colalign=None)[source]
coltitles[source]
coltitlestrings(colalign=None)[source]
column(index)[source]
colwidth(index, withtitle=False, colalign=None)[source]
colwidth_after_point(index)[source]
colwidth_before_point(index)[source]
colwidths(withtitle=False, colalign=None)[source]
dimensions(**kwargs)[source]

Get table dimensions (the space needed to print the table) in the form (number of terminal rows, number of terminal columns). All keyword arguments are passed to Table.make().

hpiece = u'\u254e'
insert_cell((row, column), data=None)[source]
insert_column(index, data, title=None, align=None, startrow=0)[source]
insert_row(index, data, title=None, startcol=0)[source]
left()[source]
make(titles=False, hb='', vb='', padding=0, hp=0, vp=0, autoalign=True, rowtitles=False, coltitles=False, hc=' ', vc='', ht=' ', vt='', border='', borderleft='', borderright='', bordertop='', borderbottom='', paddingleft=0, paddingright=0, paddingtop=0, paddingbottom=0, width=None, box=True)[source]

Create table representation.

The following formatting options exist:

rowtitles:
Show row titles. Default: False
coltitles:
Show column titles. Default: False
hc:
Horizontal cell delimiter. Default: ‘ ‘
vc:
Vertical cell delimiter. Default: ‘’
ht:
Horizontal delimiter between row titles and data cells. Default: ‘ ‘
vt:
Vertical delimiter between column titles and data cells. Default: ‘’
borderleft:
Character used as the left table border. Default: ‘’
borderright:
Character used as the right table border. Default: ‘’
bordertop:
Character used as the top table border. Default: ‘’
borderbottom:
Character used as the bottom table border. Default: ‘’
paddingleft:
Left cell padding (number of space characters). Default: 0
paddingright:
Right cell padding (number of space characters). Default: 0
paddingtop:
Top cell padding (number of space characters). Default: 0
paddingbottom:
Bottom cell padding (number of space characters). Default: 0
autoalign:
If True, infer alignment of columns from the column data. only for those columns for which no alignment has been set. Default: True
width:
If not None, set the width of the table. The rest of the characters will be cut from each line. Should be set to the terminal width for wide tables. Default: None
box:
If True, interpret certain characters in the options hc, vc, ht, vt, borderleft, borderright, bordertop, borderbottom, hb and vb as unicode box drawing characters (0x2500..0x2580). May not be available on all systems. See the section “special delimiters” for a list of characters that are interpreted. Default: True

The following shortcuts exist:

titles:
Show row and column titles. Overrides rowtitles and coltitles. Default: False
hb:
Set horizontal borders. Overrides bordertop and borderbottom. Default: ‘’
vb:
Set vertical borders. Overrides borderleft and borderright. Default: ‘’
padding:
Set cell padding (number of space characters). Overrides paddingtop, paddingbottom, paddingleft and paddingright. Default: 0
hp:
Set horizontal cell padding (number of space characters). Overrides paddingleft and paddingright. Default: 0
vp:
Set vertical cell padding (number of space characters). Overrides paddingtop and paddingbottom. Default: 0
border:
Set borders. Overrides borderleft, borderright, bordertop and borderbottom. Default: ‘’

Special delimiters:

As long as box is True (default), certain characters in the options hc, vc, ht, vt, borderleft, borderright, bordertop, borderbottom, hb and vb are interpreted as unicode box drawing characters (0x2500..0x2580). May not be available on all systems.

Further information can be found at

The following characters are interpreted:

“l”:
light single line
“h”:
heavy single line
“d”:
double line
“2”:
light double dash
“u”:
heavy double dash
“3”:
light triple dash
“t”:
heavy triple dash
“4”:
light quadruple dash
“q”:
heavy quadruple dash
ncols()[source]
nrows()[source]
right()[source]
row(index)[source]
rowinds()[source]
rowinds_and_colinds()[source]
rowtitles[source]
rowtitlescolstrings()[source]
rowtitlescolwidth()[source]
size()[source]

Return size of the table in the form (number of rows, number of columns), excluding titles.

top()[source]
vpiece = u'\u2550'
class easytable.Cell(table, (row, column), data=None)[source]
align()[source]
colind()[source]
column()[source]
data[source]
inds()[source]
instance_count[source]
instance_id[source]
row()[source]
rowind()[source]
splitpoint()[source]
table[source]
width()[source]
width_after_point()[source]
width_before_and_after_point()[source]
width_before_point()[source]
class easytable.CellDict(mapping_or_iterable=None, **kwargs)[source]

A mapping (row index, column index) --> cell object.

index(cell)[source]

Return indices (row, column) of the given cell object. Raise ValueError if the cell is not present.

class easytable.TitleDict(mapping_or_iterable=None, **kwargs)[source]

A mapping integer --> title. Keys must be integer.

class easytable.AlignDict(mapping_or_iterable=None, **kwargs)[source]

A mapping integer --> string. Keys must be integer, values must be one of the strings “left”, “right”, “center”, or “point”.

Auxiliary classes

class easytable.items_of(itemname, default=None, dtype=None)[source]

Instances of this class are callables which get a certain item of each element of a given iterable, and returns all items in form of a new iterable. If item does not exist and a default value is given, return that value.

Indices and tables

Table Of Contents

This Page