tools.formatter — Formatting Related Functions and Classes#

Module containing various formatting related utilities.

class tools.formatter.SequenceOutputter(sequence)[source]#

Bases: object

A class formatting a list of items.

It is possible to customize the appearance by changing format_string which is used by str.format with index, width and item. Each line is joined by the separator and the complete text is surrounded by the prefix and the suffix. All three are by default a new line. The index starts at 1 and for the width it’s using the width of the sequence’s length written as a decimal number. So a length of 100 will result in a with of 3 and a length of 99 in a width of 2.

It is iterating over self.sequence to generate the text. That sequence can be any iterator but the result is better when it has an order.

Create a new instance with a reference to the sequence.

format_string = '  {index:>{width}} - {item}'#
property out#

Create the text with one item on each line.

output()[source]#

Output the text of the current sequence.

Deprecated since version 9.0: Use pywikibot.info() with out property.

Return type:

None

prefix = '\n'#
separator = '\n'#
suffix = '\n'#
tools.formatter.color_format(text, *args, **kwargs)[source]#

Do str.format without having to worry about colors.

It is automatically adding \03 in front of color fields so it’s unnecessary to add them manually. Any other \03 in the text is disallowed.

You may use a variant {color} by assigning a valid color to a named parameter color.

Deprecated since version 7.2: new color format pattern like f'<<{color}>>colored text<<default>>' can be used instead.

Parameters:

text (str) – The format template string

Returns:

The formatted string

Raises:

ValueError – Wrong format string or wrong keywords

Return type:

str