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 (Any) – Object to format.

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

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

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'))