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.

classification
Title: pprint, single/multiple items per line parameter
Type: enhancement Stage: test needed
Components: Library (Lib) Versions: Python 3.2
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, dmtr, rhettinger
Priority: normal Keywords: patch

Created on 2010-03-25 06:15 by dmtr, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue_8228.dirty.patch dmtr, 2010-03-25 07:55 target trunk (2.6), revision 77310, includes issue_5131.patch
issue_8228.patch amaury.forgeotdarc, 2010-04-01 08:31
Messages (5)
msg101672 - (view) Author: Dmitry Chichkov (dmtr) Date: 2010-03-25 06:15
I've run into a case where pprint isn't really pretty. 

import pprint
pprint.PrettyPrinter().pprint([1]*100)

Prints a lengthy column of '1'; Not pretty at all. Look:

[1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1]
msg101675 - (view) Author: Dmitry Chichkov (dmtr) Date: 2010-03-25 07:55
Quick, dirty and utterly incorrect patch that works for me. Includes issue_5131.patch (defaultdict support, etc). Targets trunk (2.6), revision 77310.
msg102075 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-04-01 08:31
Please generate patches with "context diff", or better "unified diff", with the "diff -u" command.
I've done it, before the source code changes and the patch becomes impossible to apply.

Note that the new version does not respect the width:
len(pprint.pformat([1]*100).splitlines()[0]) == 81
msg102079 - (view) Author: Dmitry Chichkov (dmtr) Date: 2010-04-01 09:28
Yes. This patch is nowhere near the production level. Unfortunately it works for me. And in the moment I don't have time to improve it further. Current version doesn't check the item's width upfront, there is definitely room for improvement. 

There is also an issue with the included issue_5131.patch - pretty-printed code can not be executed, unless 'defaultdict(' ')' type-specs are removed.
msg113638 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-08-11 22:40
Am rejecting this request because it complicates pprint and makes it harder to extend.  Most use cases of pprint either don't need this or have output requirements more complicated than proposed (i.e. adding fixed width columns for tabular output, etc).

Also, the current design of pprint doesn't know in advance the width of objects, so a decision to start with multi-column may be invalidated when wider data is encountered later.
History
Date User Action Args
2022-04-11 14:56:59adminsetgithub: 52475
2010-08-11 22:40:08rhettingersetstatus: open -> closed

nosy: + rhettinger
messages: + msg113638

resolution: rejected
2010-08-07 18:02:42terry.reedysetstage: test needed
versions: + Python 3.2, - Python 2.6
2010-04-01 09:28:59dmtrsetmessages: + msg102079
2010-04-01 08:31:07amaury.forgeotdarcsetfiles: + issue_8228.patch
nosy: + amaury.forgeotdarc
messages: + msg102075

2010-03-25 07:55:51dmtrsetfiles: + issue_8228.dirty.patch
keywords: + patch
messages: + msg101675
2010-03-25 06:15:58dmtrcreate