easytable
index
/home/djung/lib/easytable/__init__.py

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 :func:`autotable` is provided that can infer an
appropiate table form the given data structure.
 
It has been attempted to find the natural tabular representation of many
possible data structures. For each kind of data structure, specialized
functions exist:
 
    :func:`docl`:
        dictionary of lists, where each list represents a named column
 
    :func:`dorl`:
        dictionary of lists, where each list represents a named row
 
    :func:`locl`:
        list of lists, where each list represents a column
 
    :func:`lorl`:
        list of lists, where each list represents a row
 
    :func:`locd`:
        list of dictionaries, where each dictionary represents a column
 
    :func:`lord`:
        list of dictionaries, where each dictionary represents a row
 
    :func:`docd`:
        dictionary of dictionaries, where each dictionary represents a named
        column
 
    :func:`dord`:
        dictionary of dictionaries, where each dictionary represents a named
        row
 
There are no ambitions to implement any sorting or filtering options.  Data
structures have to be passed already in an ordered way. Tip: In the case of
dictionaries, :class:`collections.OrderedDict` can be used to force a certain
row or column order.
 
For absolute fine control, the :class:`Table` class can be used directly to
construct the table by hand.

 
Package Contents
       
presets

 
Classes
       
__builtin__.dict(__builtin__.object)
AlignDict
CellDict
TitleDict
__builtin__.object
Cell
Table
items_of

 
class AlignDict(__builtin__.dict)
    A mapping ``integer --> string``. Keys must be integer, values must be
one of the strings "left", "right", "center", or "point".
 
 
Method resolution order:
AlignDict
__builtin__.dict
__builtin__.object

Methods defined here:
__init__(self, mapping_or_iterable=None, **kwargs)
__setitem__(self, key, value)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Methods inherited from __builtin__.dict:
__cmp__(...)
x.__cmp__(y) <==> cmp(x,y)
__contains__(...)
D.__contains__(k) -> True if D has a key k, else False
__delitem__(...)
x.__delitem__(y) <==> del x[y]
__eq__(...)
x.__eq__(y) <==> x==y
__ge__(...)
x.__ge__(y) <==> x>=y
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__gt__(...)
x.__gt__(y) <==> x>y
__iter__(...)
x.__iter__() <==> iter(x)
__le__(...)
x.__le__(y) <==> x<=y
__len__(...)
x.__len__() <==> len(x)
__lt__(...)
x.__lt__(y) <==> x<y
__ne__(...)
x.__ne__(y) <==> x!=y
__repr__(...)
x.__repr__() <==> repr(x)
__sizeof__(...)
D.__sizeof__() -> size of D in memory, in bytes
clear(...)
D.clear() -> None.  Remove all items from D.
copy(...)
D.copy() -> a shallow copy of D
fromkeys(...)
dict.fromkeys(S[,v]) -> New dict with keys from S and values equal to v.
v defaults to None.
get(...)
D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None.
has_key(...)
D.has_key(k) -> True if D has a key k, else False
items(...)
D.items() -> list of D's (key, value) pairs, as 2-tuples
iteritems(...)
D.iteritems() -> an iterator over the (key, value) items of D
iterkeys(...)
D.iterkeys() -> an iterator over the keys of D
itervalues(...)
D.itervalues() -> an iterator over the values of D
keys(...)
D.keys() -> list of D's keys
pop(...)
D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
If key is not found, d is returned if given, otherwise KeyError is raised
popitem(...)
D.popitem() -> (k, v), remove and return some (key, value) pair as a
2-tuple; but raise KeyError if D is empty.
setdefault(...)
D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D
update(...)
D.update([E, ]**F) -> None.  Update D from dict/iterable E and F.
If E present and has a .keys() method, does:     for k in E: D[k] = E[k]
If E present and lacks .keys() method, does:     for (k, v) in E: D[k] = v
In either case, this is followed by: for k in F: D[k] = F[k]
values(...)
D.values() -> list of D's values
viewitems(...)
D.viewitems() -> a set-like object providing a view on D's items
viewkeys(...)
D.viewkeys() -> a set-like object providing a view on D's keys
viewvalues(...)
D.viewvalues() -> an object providing a view on D's values

Data and other attributes inherited from __builtin__.dict:
__hash__ = None
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

 
class Cell(__builtin__.object)
     Methods defined here:
__init__(self, table, (row, column), data=None)
__len__(self)
__repr__(self)
__str__(self)
align(self)
colind(self)
column(self)
inds(self)
row(self)
rowind(self)
splitpoint(self)
width(self)
width_after_point(self)
width_before_and_after_point(self)
width_before_point(self)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)
data
instance_count
instance_id
table

 
class CellDict(__builtin__.dict)
    A mapping ``(row index, column index) --> cell object``.
 
 
Method resolution order:
CellDict
__builtin__.dict
__builtin__.object

Methods defined here:
__delitem__(self, inds)
__init__(self, mapping_or_iterable=None, **kwargs)
__setitem__(self, key, value)
index(self, cell)
Return indices (row, column) of the given cell object. Raise
ValueError if the cell is not present.

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Methods inherited from __builtin__.dict:
__cmp__(...)
x.__cmp__(y) <==> cmp(x,y)
__contains__(...)
D.__contains__(k) -> True if D has a key k, else False
__eq__(...)
x.__eq__(y) <==> x==y
__ge__(...)
x.__ge__(y) <==> x>=y
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__gt__(...)
x.__gt__(y) <==> x>y
__iter__(...)
x.__iter__() <==> iter(x)
__le__(...)
x.__le__(y) <==> x<=y
__len__(...)
x.__len__() <==> len(x)
__lt__(...)
x.__lt__(y) <==> x<y
__ne__(...)
x.__ne__(y) <==> x!=y
__repr__(...)
x.__repr__() <==> repr(x)
__sizeof__(...)
D.__sizeof__() -> size of D in memory, in bytes
clear(...)
D.clear() -> None.  Remove all items from D.
copy(...)
D.copy() -> a shallow copy of D
fromkeys(...)
dict.fromkeys(S[,v]) -> New dict with keys from S and values equal to v.
v defaults to None.
get(...)
D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None.
has_key(...)
D.has_key(k) -> True if D has a key k, else False
items(...)
D.items() -> list of D's (key, value) pairs, as 2-tuples
iteritems(...)
D.iteritems() -> an iterator over the (key, value) items of D
iterkeys(...)
D.iterkeys() -> an iterator over the keys of D
itervalues(...)
D.itervalues() -> an iterator over the values of D
keys(...)
D.keys() -> list of D's keys
pop(...)
D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
If key is not found, d is returned if given, otherwise KeyError is raised
popitem(...)
D.popitem() -> (k, v), remove and return some (key, value) pair as a
2-tuple; but raise KeyError if D is empty.
setdefault(...)
D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D
update(...)
D.update([E, ]**F) -> None.  Update D from dict/iterable E and F.
If E present and has a .keys() method, does:     for k in E: D[k] = E[k]
If E present and lacks .keys() method, does:     for (k, v) in E: D[k] = v
In either case, this is followed by: for k in F: D[k] = F[k]
values(...)
D.values() -> list of D's values
viewitems(...)
D.viewitems() -> a set-like object providing a view on D's items
viewkeys(...)
D.viewkeys() -> a set-like object providing a view on D's keys
viewvalues(...)
D.viewvalues() -> an object providing a view on D's values

Data and other attributes inherited from __builtin__.dict:
__hash__ = None
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

 
class Table(__builtin__.object)
     Methods defined here:
__init__(self, cells=None, rowtitles=None, coltitles=None, colalign=None)
append_column(self, data, title=None, align=None, startrow=0)
append_row(self, data, title=None, startcol=0)
bottom(self)
colinds(self)
colstrings(self, index, withtitle=False, colalign=None)
coltitlestrings(self, colalign=None)
column(self, index)
colwidth(self, index, withtitle=False, colalign=None)
colwidth_after_point(self, index)
colwidth_before_point(self, index)
colwidths(self, withtitle=False, colalign=None)
dimensions(self, **kwargs)
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 :py:meth:`Table.make`.
insert_cell(self, (row, column), data=None)
insert_column(self, index, data, title=None, align=None, startrow=0)
insert_row(self, index, data, title=None, startcol=0)
left(self)
make(self, 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)
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
http://en.wikipedia.org/wiki/Box-drawing_character
http://unicode.org/charts/PDF/U2500.pdfhttp://unicode.org/charts/PDF
/U2500.pdfhttp://unicode.org/charts/PDF/U2500.pdf
 
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(self)
nrows(self)
right(self)
row(self, index)
rowinds(self)
rowinds_and_colinds(self)
rowtitlescolstrings(self)
rowtitlescolwidth(self)
size(self)
Return size of the table in the form (number of rows, number of
columns), excluding titles.
top(self)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)
cells
colalign
coltitles
rowtitles

Data and other attributes defined here:
hpiece = u'\u254e'
vpiece = u'\u2550'

 
class TitleDict(__builtin__.dict)
    A mapping ``integer --> title``. Keys must be integer.
 
 
Method resolution order:
TitleDict
__builtin__.dict
__builtin__.object

Methods defined here:
__init__(self, mapping_or_iterable=None, **kwargs)
__setitem__(self, key, value)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Methods inherited from __builtin__.dict:
__cmp__(...)
x.__cmp__(y) <==> cmp(x,y)
__contains__(...)
D.__contains__(k) -> True if D has a key k, else False
__delitem__(...)
x.__delitem__(y) <==> del x[y]
__eq__(...)
x.__eq__(y) <==> x==y
__ge__(...)
x.__ge__(y) <==> x>=y
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__gt__(...)
x.__gt__(y) <==> x>y
__iter__(...)
x.__iter__() <==> iter(x)
__le__(...)
x.__le__(y) <==> x<=y
__len__(...)
x.__len__() <==> len(x)
__lt__(...)
x.__lt__(y) <==> x<y
__ne__(...)
x.__ne__(y) <==> x!=y
__repr__(...)
x.__repr__() <==> repr(x)
__sizeof__(...)
D.__sizeof__() -> size of D in memory, in bytes
clear(...)
D.clear() -> None.  Remove all items from D.
copy(...)
D.copy() -> a shallow copy of D
fromkeys(...)
dict.fromkeys(S[,v]) -> New dict with keys from S and values equal to v.
v defaults to None.
get(...)
D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None.
has_key(...)
D.has_key(k) -> True if D has a key k, else False
items(...)
D.items() -> list of D's (key, value) pairs, as 2-tuples
iteritems(...)
D.iteritems() -> an iterator over the (key, value) items of D
iterkeys(...)
D.iterkeys() -> an iterator over the keys of D
itervalues(...)
D.itervalues() -> an iterator over the values of D
keys(...)
D.keys() -> list of D's keys
pop(...)
D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
If key is not found, d is returned if given, otherwise KeyError is raised
popitem(...)
D.popitem() -> (k, v), remove and return some (key, value) pair as a
2-tuple; but raise KeyError if D is empty.
setdefault(...)
D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D
update(...)
D.update([E, ]**F) -> None.  Update D from dict/iterable E and F.
If E present and has a .keys() method, does:     for k in E: D[k] = E[k]
If E present and lacks .keys() method, does:     for (k, v) in E: D[k] = v
In either case, this is followed by: for k in F: D[k] = F[k]
values(...)
D.values() -> list of D's values
viewitems(...)
D.viewitems() -> a set-like object providing a view on D's items
viewkeys(...)
D.viewkeys() -> a set-like object providing a view on D's keys
viewvalues(...)
D.viewvalues() -> an object providing a view on D's values

Data and other attributes inherited from __builtin__.dict:
__hash__ = None
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

 
class items_of(__builtin__.object)
    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.
 
  Methods defined here:
__call__(self, iterable)
__init__(self, itemname, default=None, dtype=None)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
Functions
       
all_of_type(seq, dtype)
Check if all items of the given sequence *seq* are of the type
*dtype*. *dtype* can also be a list of possible types.
alldict(seq)
alliter(seq)
autotable(data_structure, **kwargs)
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 :py:meth:`Table.make`.
docd(dict_of_dicts, **kwargs)
Return table representation of the given dictionary of dictionaries,
where each dictionary represents a **column**. Keyword arguments are passed
to :py:meth:`Table.make`.
docl(dict_of_lists, **kwargs)
Return table representation of the given dictionary of lists, where each
list represents a named **column**. Keyword arguments are passed to
:py:meth:`Table.make`.
dord(dict_of_dicts, **kwargs)
Return table representation of the given dictionary of dictionaries,
where each dictionary represents a **row**. Keyword arguments are passed to
:py:meth:`Table.make`.
dorl(dict_of_lists, **kwargs)
Return table representation of the given dictionary of lists, where each
list represents a named **row**. Keyword arguments are passed to
:py:meth:`Table.make`.
isdict(obj)
Check if the given object *obj* is a dictionar.
isiter(obj)
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.
locd(list_of_dicts, **kwargs)
Return table representation of the given list of dictionaries, where
each dictionary represents a **column**. Keyword arguments are passed to
:py:meth:`Table.make`.
locl(list_of_lists, **kwargs)
Return table representation of the given list of lists, where each list
represents a **column**. Keyword arguments are passed to
:py:meth:`Table.make`.
lord(list_of_dicts, **kwargs)
Return table representation of the given list of dictionaries, where
each dictionary represents a **row**. Keyword arguments are passed to
:py:meth:`Table.make`.
lorl(list_of_lists, **kwargs)
Return table representation of the given list of lists, where each list
represents a **row**. Keyword arguments are passed to
:py:meth:`Table.make`.

 
Data
        DEFAULT_ALIGN = 'left'