Skip to content
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

Closed
serhiy-storchaka opened this issue Sep 29, 2013 · 14 comments
Closed

Add compact mode to pprint #63331

serhiy-storchaka opened this issue Sep 29, 2013 · 14 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@serhiy-storchaka
Copy link
Member

BPO 19132
Nosy @pitrou, @bitdancer, @serhiy-storchaka
Files
  • pprint_compact.patch
  • pprint_compact_2.patch
  • pprint_compact_3.patch
  • 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:

    assignee = None
    closed_at = <Date 2013-10-02.08:58:22.288>
    created_at = <Date 2013-09-29.20:05:49.946>
    labels = ['type-feature', 'library']
    title = 'Add compact mode to pprint'
    updated_at = <Date 2014-07-23.19:01:55.496>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2014-07-23.19:01:55.496>
    actor = 'python-dev'
    assignee = 'none'
    closed = True
    closed_date = <Date 2013-10-02.08:58:22.288>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2013-09-29.20:05:49.946>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = ['31924', '31925', '31935']
    hgrepos = []
    issue_num = 19132
    keywords = ['patch']
    message_count = 14.0
    messages = ['198641', '198643', '198702', '198711', '198713', '198717', '198726', '198789', '198790', '198821', '198836', '198855', '198858', '223761']
    nosy_count = 4.0
    nosy_names = ['pitrou', 'r.david.murray', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue19132'
    versions = ['Python 3.4']

    @serhiy-storchaka
    Copy link
    Member Author

    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']

    @serhiy-storchaka serhiy-storchaka added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Sep 29, 2013
    @pitrou
    Copy link
    Member

    pitrou commented Sep 29, 2013

    I think it looks good on the principle.

    @bitdancer
    Copy link
    Member

    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',
    'very very long string which is continued on '
    'several lines',
    'and again', 'and again', 'and again',
    'and again']

    @serhiy-storchaka
    Copy link
    Member Author

    Here is a patch. Please review and correct the documentation.

    @serhiy-storchaka
    Copy link
    Member Author

    I'd suggest that compact mode also indent the string continuation lines:

    Please open new issue for this.

    @bitdancer
    Copy link
    Member

    As noted in the review, I'm not as keen on having dictionaries displayed in compact form.

    @serhiy-storchaka
    Copy link
    Member Author

    Updated patch addresses David's comments. Thank you David.

    As noted in the review, I'm not as keen on having dictionaries displayed in compact form.

    This makes sense. If no one will argue for compactifying mappings I'll remove this part of the patch.

    @pitrou
    Copy link
    Member

    pitrou commented Oct 1, 2013

    As noted in the review, I'm not as keen on having dictionaries displayed
    in compact form.

    Agreed with David.

    @serhiy-storchaka
    Copy link
    Member Author

    Updated patch doesn't compactify dicts.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 2, 2013

    New changeset ae0306c8f7a3 by Serhiy Storchaka in branch 'default':
    Issue bpo-19132: The pprint module now supports compact mode.
    http://hg.python.org/cpython/rev/ae0306c8f7a3

    @bitdancer
    Copy link
    Member

    Sorry I missed this on the review, but you are missing versionchanged tags (or versionadded, whichever you prefer :) and a what's new entry.

    @serhiy-storchaka
    Copy link
    Member Author

    I had added a what's new entry.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 2, 2013

    New changeset 6e7b1aadea2f by Serhiy Storchaka in branch 'default':
    Issue bpo-19132: Add versionchanged tags.
    http://hg.python.org/cpython/rev/6e7b1aadea2f

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jul 23, 2014

    New changeset 60301b9982b2 by Terry Jan Reedy in branch '2.7':
    Issue bpo-21597: Turtledemo text pane can now be widened to view or copy complete
    http://hg.python.org/cpython/rev/60301b9982b2

    New changeset 0fb515063324 by Terry Jan Reedy in branch '3.4':
    Issue bpo-21597: Turtledemo text pane can now be widened to view or copy complete
    http://hg.python.org/cpython/rev/0fb515063324

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants