html_nested_tables documentation¶
Source available on GitHub.
-
class
html_nested_tables.base.
TableDict
(*args, **kwds)[source]¶ TableDict objects are ordered dicts with methods that renders HTML tables.
Here is an ugly schema to define the terms I’m using:
hh1 hh2 hh3 hh4 hh11 hh12 hh21 hh22 hh31 hh32 hh41 hh42 vh1 dA dB dC dE dF dG dH dI vh2 dJ dK dL dM dN dO dP dQ vh3 dR dS dT dU dV dW dX dY hh1, hh11, hh2 […] are horizontal headers, vh1, vh2, […] are vertical headers, and dA, dB, […] are data.
-
generate_html
()[source]¶ Generates an HTML table from the contents of
self
.It creates an empty cell first, adds horizontal headers, then adds both vertical headers and data in the same time.
This whole thing could be implemented using BeautifulSoup and its outstanding inplace modification possibilities. That may be much more readable, but also much slower.
Returns: A HTML table. Return type: unicode
-
-
class
html_nested_tables.base.
HorizontalTableDict
(*args, **kwds)[source]¶ Same as
TableDict
, but with a direction.The direction is used to specify whether the headers of the first depth of the current object should be put on the horizontal or vertical axis.
-
class
html_nested_tables.base.
VerticalTableDict
(*args, **kwds)[source]¶ Same as
TableDict
, but with a direction.The direction is used to specify whether the headers of the first depth of the current object should be put on the horizontal or vertical axis.
-
html_nested_tables.base.
h
¶ alias of
HorizontalTableDict
-
html_nested_tables.base.
v
¶ alias of
VerticalTableDict
-
html_nested_tables.base.
get_all_structures
(datadict)[source]¶ Returns all the possible structures for a datadict.
Parameters: datadict – Nested dicts or association lists. Association lists have the advantage of being ordered. Returns: All possible structures. Return type: list
-
html_nested_tables.base.
build_table_dict
(datadict, structure)[source]¶ Automatically builds a TableDict from
datadict
andstructure
.Parameters: - datadict (dict or tuple or list) – Nested dicts or association lists. Association lists have the advantage of being ordered.
- structure (list or tuple) – Structure of the headers of the returned object. This
must be a sequence of
h
and/orv
, one per depth level ofdatadict
.
Returns: Nested
TableDict
s with horizontal and/or vertical structures applied, according tostructure
.Return type:
-
html_nested_tables.base.
build_optimal_table_dict
(datadict)[source]¶ Automatically builds the less ugly table possible from
datadict
.Parameters: datadict (dict or tuple or list) – Nested dicts or association lists. Association lists have the advantage of being ordered. Returns: Nested TableDict
with horizontal and/or vertical structures applied, according tostructure
.Return type: HorizontalTableDict or VerticalTableDict