Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-113056: Add a new parameter *compact* toplistlib.dump#126075

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Wulian233 wants to merge7 commits intopython:main
base:main
Choose a base branch
Loading
fromWulian233:add-compact-mode

Conversation

Wulian233
Copy link
Contributor

@Wulian233Wulian233 commentedOct 28, 2024
edited
Loading

compact=False (default)

false

compact=True (new)

true


📚 Documentation preview 📚:https://cpython-previews--126075.org.readthedocs.build/

@nineteendo
Copy link
Contributor

Wouldn'tindent=None likejson.dumps() be more flexible?

@Wulian233
Copy link
ContributorAuthor

Wulian233 commentedOct 28, 2024
edited
Loading

indent=0 (edit) will also add line breaks.compact will not, the same parameter (and function) is also present in pprint.

https://docs.python.org/3.14/library/json.html#basic-usage
https://docs.python.org/3.14/library/pprint.html#functions

Also exist in json.tool

Use with --no-indent or --compact to produce valid JSON Lines output.')

https://github.com/python/cpython/blob/main/Lib/json/tool.py#L27-L27

@nineteendo
Copy link
Contributor

No, that'sindent=0:

An indent level of 0, negative, or "" will only insert newlines. None (the default) selects the most compact representation.

Wulian233 reacted with thumbs up emoji

@devdanzin
Copy link
Contributor

Would it make sense to test that whencompact=True indentation/newlines are absent in the output? And maybe test that the compact output is shorter that the non-compact?

Copy link
Member

@serhiy-storchakaserhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I am not a macOS user, so I have no opinion about this feature.

@nineteendo
Copy link
Contributor

Wulian, you still haven't responded to why we can't addindent="\t" instead, this is familiar to uses of the json library.

@Wulian233
Copy link
ContributorAuthor

Wulian233 commentedOct 30, 2024
edited
Loading

I think settingcompact=True would be easier to understand the purpose, andpprint also has this feature, which outputs a format without indentation and line breaks.

Same name also exist in json.tool

Use with --no-indent or --compact to produce valid JSON Lines output.')

https://github.com/python/cpython/blob/main/Lib/json/tool.py#L27-L27


indent=0 andindent=None are not very clear, and the difference is adding line breaks, just like me, I got confused about the difference between the two in the above. I added this function mentioned it in the issue, where indentation takes up a lot of space, of course, adding indent would be more flexible, and using compact would be more direct, andindent="\t" feels like it's getting complicated again. I haven't used plist, but XML format is usually indented with four spaces?

@nineteendo
Copy link
Contributor

pprint also has this feature, which outputs a format without indentation and line breaks.

compact forpprint() formats the elements in a grid layout. "compact" iswidth=sys.maxsize.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@serhiy-storchakaserhiy-storchakaserhiy-storchaka left review comments

@ronaldoussorenronaldoussorenAwaiting requested review from ronaldoussoren

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@Wulian233@nineteendo@devdanzin@serhiy-storchaka

[8]ページ先頭

©2009-2025 Movatter.jp