polymerist.genutils.textual.prettyprint
For generating human-readable string representations of other Python objects
Attributes
Classes
For specifying string justification |
Functions
|
Takes a string and a target length and returns a new string which begins |
|
Generate a pretty-printable string from a (possibly nested) dictionary, |
|
Create an inline string describing the mappping in a dict |
Module Contents
- class polymerist.genutils.textual.prettyprint.Justification[source]
Bases:
enum.StrEnumFor 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