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

pprint, single/multiple items per line parameter #52475

Closed
dmtr mannequin opened this issue Mar 25, 2010 · 5 comments
Closed

pprint, single/multiple items per line parameter #52475

dmtr mannequin opened this issue Mar 25, 2010 · 5 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@dmtr
Copy link
Mannequin

dmtr mannequin commented Mar 25, 2010

BPO 8228
Nosy @rhettinger, @amauryfa
Files
  • issue_8228.dirty.patch: target trunk (2.6), revision 77310, includes issue_5131.patch
  • issue_8228.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 2010-08-11.22:40:08.633>
    created_at = <Date 2010-03-25.06:15:58.876>
    labels = ['type-feature', 'library']
    title = 'pprint, single/multiple items per line parameter'
    updated_at = <Date 2010-08-11.22:40:08.632>
    user = 'https://bugs.python.org/dmtr'

    bugs.python.org fields:

    activity = <Date 2010-08-11.22:40:08.632>
    actor = 'rhettinger'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-08-11.22:40:08.633>
    closer = 'rhettinger'
    components = ['Library (Lib)']
    creation = <Date 2010-03-25.06:15:58.876>
    creator = 'dmtr'
    dependencies = []
    files = ['16640', '16719']
    hgrepos = []
    issue_num = 8228
    keywords = ['patch']
    message_count = 5.0
    messages = ['101672', '101675', '102075', '102079', '113638']
    nosy_count = 3.0
    nosy_names = ['rhettinger', 'amaury.forgeotdarc', 'dmtr']
    pr_nums = []
    priority = 'normal'
    resolution = 'rejected'
    stage = 'test needed'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue8228'
    versions = ['Python 3.2']

    @dmtr
    Copy link
    Mannequin Author

    dmtr mannequin commented Mar 25, 2010

    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]

    @dmtr dmtr mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Mar 25, 2010
    @dmtr
    Copy link
    Mannequin Author

    dmtr mannequin commented Mar 25, 2010

    Quick, dirty and utterly incorrect patch that works for me. Includes issue_5131.patch (defaultdict support, etc). Targets trunk (2.6), revision 77310.

    @amauryfa
    Copy link
    Member

    amauryfa commented Apr 1, 2010

    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

    @dmtr
    Copy link
    Mannequin Author

    dmtr mannequin commented Apr 1, 2010

    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.

    @rhettinger
    Copy link
    Contributor

    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.

    @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

    2 participants