colour.utilities.multiline_str#
- colour.utilities.multiline_str(object_: Any, attributes: List[dict], header_underline: str = '=', section_underline: str = '-', separator: str = ' : ') str[source]#
Generate a formatted multi-line string representation of the specified object.
- Parameters:
object – Object to format into a string representation.
attributes (List[dict]) – Attributes to format, provided as a list of dictionaries with formatting specifications.
header_underline (str) – Underline character to use for header sections.
section_underline (str) – Underline character to use for subsections.
separator (str) – Separator to use when formatting the attributes and their values.
object_ (Any)
- Returns:
Formatted multi-line string representation.
- Return type:
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