colour.utilities.multiline_repr#

colour.utilities.multiline_repr(object_: Any, attributes: List[dict], reduce_array_representation: bool = True) str[source]#

Return an (almost) evaluable string representation of the given object.

Parameters:
  • object – Object to format.

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

  • reduce_array_representation (bool) – Whether to remove the Numpy array( and ) affixes.

  • object_ (Any) –

Returns:

(Almost) evaluable string representation.

Return type:

class`str`

Examples

>>> class Data:
...     def __init__(self, a: str, b: int, c: list):
...         self._a = a
...         self._b = b
...         self._c = c
...
...     def __repr__(self) -> str:
...         return multiline_repr(
...             self,
...             [
...                 {"name": "_a"},
...                 {"name": "_b"},
...                 {
...                     "name": "_c",
...                     "formatter": lambda x: repr(x)
...                     .replace("[", "(")
...                     .replace("]", ")"),
...                 },
...             ],
...         )
>>> Data("Foo", 1, ["John", "Doe"])
Data('Foo',
     1,
     ('John', 'Doe'))