-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add compact mode to pprint #63331
Comments
pprint produces not very nice output for collections with a large number of short elements (see msg198556). For example pprint.pprint(list(range(40))) outputs more than 40 short lines, while print(repr(list(range(40)))) takes only 2 lines on 80-column terminal. I propose to add new boolean option "compact". With compact=True pprint will try combine as much short one-line subelements in one line as possible. Every multiline element will be printed on separated lines. Examples: >>> pprint.pprint(list(range(40)), width=50, compact=True)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
38, 39]
>>> pprint.pprint(['one string', 'other string', 'very very long string which continued on several lines', 'and again', 'and again', 'and again', 'and again'], width=50, compact=True)
['one string', 'other string',
'very very long string which is continued on '
'several lines',
'and again', 'and again', 'and again',
'and again'] |
I think it looks good on the principle. |
I like it. If it isn't too difficult, I'd suggest that compact mode also indent the string continuation lines: ['one string', 'other string', |
Here is a patch. Please review and correct the documentation. |
Please open new issue for this. |
As noted in the review, I'm not as keen on having dictionaries displayed in compact form. |
Updated patch addresses David's comments. Thank you David.
This makes sense. If no one will argue for compactifying mappings I'll remove this part of the patch. |
Agreed with David. |
Updated patch doesn't compactify dicts. |
New changeset ae0306c8f7a3 by Serhiy Storchaka in branch 'default': |
Sorry I missed this on the review, but you are missing versionchanged tags (or versionadded, whichever you prefer :) and a what's new entry. |
I had added a what's new entry. |
New changeset 6e7b1aadea2f by Serhiy Storchaka in branch 'default': |
New changeset 60301b9982b2 by Terry Jan Reedy in branch '2.7': New changeset 0fb515063324 by Terry Jan Reedy in branch '3.4': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: