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.
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().
Return table representation of the given dictionary of lists, where each list represents a named column. Keyword arguments are passed to Table.make().
Return table representation of the given dictionary of lists, where each list represents a named row. Keyword arguments are passed to Table.make().
Return table representation of the given list of lists, where each list represents a column. Keyword arguments are passed to Table.make().
Return table representation of the given list of lists, where each list represents a row. Keyword arguments are passed to Table.make().
Return table representation of the given list of dictionaries, where each dictionary represents a column. Keyword arguments are passed to Table.make().
Return table representation of the given list of dictionaries, where each dictionary represents a row. Keyword arguments are passed to Table.make().
Return table representation of the given dictionary of dictionaries, where each dictionary represents a column. Keyword arguments are passed to Table.make().
Return table representation of the given dictionary of dictionaries, where each dictionary represents a row. Keyword arguments are passed to Table.make().
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().
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
Return size of the table in the form (number of rows, number of columns), excluding titles.
A mapping (row index, column index) --> cell object.
A mapping integer --> title. Keys must be integer.
A mapping integer --> string. Keys must be integer, values must be one of the strings “left”, “right”, “center”, or “point”.