Class FormatterList

New in version 0.6.6.

class ooodev.formatters.formatter_list.FormatterList(format, idx_rule=OnlyIgnoreKind.IGNORE, idxs=<factory>, custom_formats=<factory>)[source]
Parameters:
__init__(format, idx_rule=OnlyIgnoreKind.IGNORE, idxs=<factory>, custom_formats=<factory>)
Parameters:
Return type:

None

apply_format(val, current_index=-1)[source]

Applies formatting to val if format has been set

Parameters:
  • val (Any) – Any value

  • current_index (int, optional) – When value is equal or greater then 0 then formatting is applied following rules for indexes.

Returns:

Formatted string

Return type:

str

custom_formats: List[FormatListItem]
format: str | Tuple[str, ...]

Format option such as .2f

Multiple formats can be added such as (".2f", "<10"). Formats are applied in the order they are added. In this case first float is formatted as string with two decimal places, and then value is padded to the right with spaces.

idx_rule: OnlyIgnoreKind = 2

Determines what indexes are affected.

idxs: Tuple[int, ...]

Indexes to apply formatting to or ignore, depending on index_rule.