core.table module

Provides an object oriented way to print out tables.

class core.table.Alignment[source]

Bases: enum.Enum

Contains constants to specify the aligment of table items.

_member_type_

alias of object

CENTER()

S.center(width[, fillchar]) -> str

Return S centered in a string of length width. Padding is done using the specified fill character (default is a space)

LEFT()

S.ljust(width[, fillchar]) -> str

Return S left-justified in a Unicode string of length width. Padding is done using the specified fill character (default is a space).

RIGHT()

S.rjust(width[, fillchar]) -> str

Return S right-justified in a string of length width. Padding is done using the specified fill character (default is a space).

_generate_next_value_(name, start, count, last_values)
_member_map_ = OrderedDict()
_member_names_ = []
_value2member_map_ = {}
class core.table.AsciiTable(*columns)[source]

Bases: object

Represents a table.

__init__(*columns)[source]

Add the given objects as columns to the table.

If a given column is not a Column object, it will be created.

add_row(*items)[source]

Append the given items to the table’s columns.

format(header_separator='=', column_separator='|')[source]

Format the table and returns an ASCII table string.

Parameters:
  • header_separator (str) – A single character that defines the character that should be used to create the horizontal separator.
  • column_separator (str) – A single character that defines the character that should be used to create the vertical separators.
class core.table.Column(name, alignment=<method 'center' of 'str' objects>, left_padding=2, right_padding=2)[source]

Bases: list

Represents a column of a table.

__init__(name, alignment=<method 'center' of 'str' objects>, left_padding=2, right_padding=2)[source]

Intialize the column.

Parameters:
  • name (str) – Name of the column.
  • alignment (int) – The alignment of the column name.
  • left_padding (int) – Number of spaces for left padding.
  • right_padding (int) – Number of spaces for right padding.
_format()[source]

Return the name of the column and all items of the column.

All items (including the name) will be formatted properly before being returned.

_get_max_padding()[source]

Return the length of the longest item in the column.

The name of the column is used to determine the length, as well.

class core.table.Item(value, alignment=<method 'ljust' of 'str' objects>)[source]

Bases: object

Represents a value/item of a column.

__init__(value, alignment=<method 'ljust' of 'str' objects>)[source]

Initialize the item.

Parameters:
  • value – The value this item should have.
  • aligment (int) – The aligment of the item in the table.
_format(padding, left_padding, right_padding)[source]

Format the item.

Parameters:
  • padding (int) – The length of the longest item in the column.
  • left_padding (int) – A number that defines how many spaces should be added to the left of the item.
  • right_padding (int) – A number that defines how many spaces should be added to the right of the item.