colour.utilities.multiline_str#

colour.utilities.multiline_str(object_: Any, attributes: List[Dict], header_underline: str = '=', section_underline: str = '-', separator: str = ' : ') str[source]#

Return a formatted string representation of the given object.

Parameters:
  • object – Object to format.

  • attributes (List[Dict]) – Attributes to format.

  • header_underline (str) – Underline character to use for a header.

  • section_underline (str) – Underline character to use for a section.

  • separator (str) – Separator to use when formatting the attributes and their values.

  • object_ (Any) –

Returns:

Formatted string representation.

Return type:

str

Examples

>>> class Data:
...     def __init__(self, a: str, b: int, c: list):
...         self._a = a
...         self._b = b
...         self._c = c
...
...     def __str__(self) -> str:
...         return multiline_str(
...             self,
...             [
...                 {
...                     "formatter": lambda x: (
...                         f"Object - {self.__class__.__name__}"
...                     ),
...                     "header": True,
...                 },
...                 {"line_break": True},
...                 {"label": "Data", "section": True},
...                 {"line_break": True},
...                 {"label": "String", "section": True},
...                 {"name": "_a", "label": 'String "a"'},
...                 {"line_break": True},
...                 {"label": "Integer", "section": True},
...                 {"name": "_b", "label": 'Integer "b"'},
...                 {"line_break": True},
...                 {"label": "List", "section": True},
...                 {
...                     "name": "_c",
...                     "label": 'List "c"',
...                     "formatter": lambda x: "; ".join(x),
...                 },
...             ]
...         )
>>> print(Data("Foo", 1, ["John", "Doe"]))
Object - Data
=============

Data
----

String
------
String "a"  : Foo

Integer
-------
Integer "b" : 1

List
----
List "c"    : John; Doe