You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With reprlib.Repr, it's possible to print object representations with a limit of recursive depth to increase readability of large objects. "This is used in the Python debugger and may be useful in other contexts as well."[1] For example, I'm using reprlib to log lines for debugging. In the same line of thought, it makes sense to be able to format the output to increase readability even further. One measure to do so is to insert line breaks with indentation.
However, in the first example above, the inner dict has not been expanded by line breaks and indentation. In the second example, after reducing depth, everything is suddenly printed onto one line only. This is the case, because the motivation and goal of pprint is to optimize output for a given width to pretty print - not to produce consistent output for debugging purposes. This becomes even more apparent when reducing width:
Note how strings that are too long for width, like "abc def ghi" in example, get split into multiple lines. This is not optimal for logging output where the width of the output (i.e. the actual line length) is usually not restricted.
Using json.dumps produces a similar output as the requested indentation feature for reprlib:
OT squared: Despite their different design goals, maybe we could try to unify pprint and reprlib? Despite their differences they seem to have considerable overlap.
With
reprlib.Repr
, it's possible to print object representations with a limit of recursive depth to increase readability of large objects. "This is used in the Python debugger and may be useful in other contexts as well."[1] For example, I'm usingreprlib
to log lines for debugging. In the same line of thought, it makes sense to be able to format the output to increase readability even further. One measure to do so is to insert line breaks with indentation.Example
At first glance,
pprint.PrettyPrinter
might be an alternative solution:However, in the first example above, the inner
dict
has not been expanded by line breaks and indentation. In the second example, after reducingdepth
, everything is suddenly printed onto one line only. This is the case, because the motivation and goal ofpprint
is to optimize output for a givenwidth
to pretty print - not to produce consistent output for debugging purposes. This becomes even more apparent when reducingwidth
:Note how strings that are too long for
width
, like"abc def ghi"
inexample
, get split into multiple lines. This is not optimal for logging output where the width of the output (i.e. the actual line length) is usually not restricted.Using
json.dumps
produces a similar output as the requested indentation feature forreprlib
:However, it is subject to the known restrictions when converting Python objects to JSON:
Therefore, it would be useful to add the following indentation feature to
reprlib
:The text was updated successfully, but these errors were encountered: