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 could use line continuation for long string literals
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: fdrake, pitrou, python-dev, rhettinger
Priority: normal Keywords: patch

Created on 2013-02-07 12:51 by pitrou, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
str_pprint.patch pitrou, 2013-03-19 22:41 review
str_pprint2.patch pitrou, 2013-03-20 21:57 review
Messages (8)
msg181599 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-02-07 12:51
Currently:

>>> pprint.pprint({"a": "xxx " * 50})
{'a': 'xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx '}

It would be nicer if it produced something like:

>>> pprint.pprint({"a": "xxx " * 50})
{'a': 'xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx '
      'xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx '
      'xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx '
      'xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx '
      'xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx '}

(for the record, the real-world use case I encountered was when printing some pyudev data)
msg181605 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2013-02-07 13:25
I like this.

It would be especially nice if it were smart enough to split the segments after sequences of line-ends (r'(\r?\n)+').
msg181643 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-02-07 19:49
I was thinking we could re-use textwrap, actually.
msg184695 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-03-19 22:41
Here is a patch.
msg184808 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-03-20 21:57
Here is a new patch with more tests and updated docs.
msg185076 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-03-23 19:35
New changeset 5a2296093645 by Antoine Pitrou in branch 'default':
Issue #17150: pprint now uses line continuations to wrap long string literals.
http://hg.python.org/cpython/rev/5a2296093645
msg185077 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-03-23 19:37
Ok, I've committed the patch.
msg185141 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2013-03-24 15:55
This is a nice addition.  Thank you.
History
Date User Action Args
2022-04-11 14:57:41adminsetgithub: 61352
2013-03-24 15:55:00rhettingersetnosy: + rhettinger
messages: + msg185141
2013-03-23 19:37:04pitrousetstatus: open -> closed
resolution: fixed
messages: + msg185077

stage: patch review -> resolved
2013-03-23 19:35:01python-devsetnosy: + python-dev
messages: + msg185076
2013-03-20 21:57:41pitrousetfiles: + str_pprint2.patch

messages: + msg184808
2013-03-19 22:41:19pitrousetfiles: + str_pprint.patch
keywords: + patch
messages: + msg184695

stage: patch review
2013-02-07 19:49:37pitrousetmessages: + msg181643
2013-02-07 13:25:25fdrakesetmessages: + msg181605
2013-02-07 12:51:07pitroucreate