polymerist.genutils.textual.prettyprint

For generating human-readable string representations of other Python objects

Attributes

Just

Classes

Justification

For specifying string justification

Functions

procrustean_string(→ int)

Takes a string and a target length and returns a new string which begins

dict_to_indented_str(→ str)

Generate a pretty-printable string from a (possibly nested) dictionary,

stringify_dict(→ str)

Create an inline string describing the mappping in a dict

Module Contents

class polymerist.genutils.textual.prettyprint.Justification[source]

Bases: enum.StrEnum

For specifying string justification

LEFT = '<'
CENTER = '^'
RIGHT = '>'
polymerist.genutils.textual.prettyprint.Just
polymerist.genutils.textual.prettyprint.procrustean_string(string: str, length: int, padding: str = ' ', just: Justification = Justification.LEFT) int[source]

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

Return type:

str

polymerist.genutils.textual.prettyprint.dict_to_indented_str(dict_to_stringify: dict[Any, Any], level_delimiter: str = '\t', line_sep: str = '\n') str[source]

Generate a pretty-printable string from a (possibly nested) dictionary, with each level of nesting indicated by “level_delimiter”

polymerist.genutils.textual.prettyprint.stringify_dict(anydict: dict[Any, Any], sep: str = ', ', joiner: str = '-->') str[source]

Create an inline string describing the mappping in a dict