This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients serhiy.storchaka
Date 2013-09-29.20:05:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1380485149.97.0.648520685176.issue19132@psf.upfronthosting.co.za>
In-reply-to
Content
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']
History
Date User Action Args
2013-09-29 20:05:50serhiy.storchakasetrecipients: + serhiy.storchaka
2013-09-29 20:05:49serhiy.storchakasetmessageid: <1380485149.97.0.648520685176.issue19132@psf.upfronthosting.co.za>
2013-09-29 20:05:49serhiy.storchakalinkissue19132 messages
2013-09-29 20:05:49serhiy.storchakacreate