polymerist.genutils.textual.prettyprint ======================================= .. py:module:: polymerist.genutils.textual.prettyprint .. autoapi-nested-parse:: For generating human-readable string representations of other Python objects Attributes ---------- .. autoapisummary:: polymerist.genutils.textual.prettyprint.Just Classes ------- .. autoapisummary:: polymerist.genutils.textual.prettyprint.Justification Functions --------- .. autoapisummary:: polymerist.genutils.textual.prettyprint.procrustean_string polymerist.genutils.textual.prettyprint.dict_to_indented_str polymerist.genutils.textual.prettyprint.stringify_dict Module Contents --------------- .. py:class:: Justification Bases: :py:obj:`enum.StrEnum` For specifying string justification .. py:attribute:: LEFT :value: '<' .. py:attribute:: CENTER :value: '^' .. py:attribute:: RIGHT :value: '>' .. py:data:: Just .. py:function:: procrustean_string(string: str, length: int, padding: str = ' ', just: Justification = Justification.LEFT) -> int Takes a string and a target length and returns a new string which begins with the same characters as the original string but is clamped to the target length, truncating or padding if the original string is too long or short, respectively :Parameters: * **string** (*str*) -- The string to stretch or cut * **length** (*int*) -- The target number of characters in the final string * **padding** (*str, default=" "*) -- A single character which shold be used as padding when strings are too short, by default just a space MUST BE EXACTLY ONE CHARACTER! * **just** (*Justification, default=Justification.LEFT*) -- Enum specifier of how to justify a padded string Options are Justification.LEFT, Justification.CENTER, or Justification.RIGHT :returns: **fmt_str** -- A string which begins with the same characters as "string" but has precisely the specified length, with specified padding as specified :rtype: str .. py:function:: dict_to_indented_str(dict_to_stringify: dict[Any, Any], level_delimiter: str = '\t', line_sep: str = '\n') -> str Generate a pretty-printable string from a (possibly nested) dictionary, with each level of nesting indicated by "level_delimiter" .. py:function:: stringify_dict(anydict: dict[Any, Any], sep: str = ', ', joiner: str = '-->') -> str Create an inline string describing the mappping in a dict