New submission from Serhiy Storchaka: 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'] ---------- components: Library (Lib) messages: 198641 nosy: serhiy.storchaka priority: normal severity: normal stage: needs patch status: open title: Add compact mode to pprint type: enhancement versions: Python 3.4 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue19132> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com