Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-113056: Add a new parameter *compact* to plistlib.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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Wulian233
Copy link
Contributor

@Wulian233 Wulian233 commented Oct 28, 2024

compact=False (default)

false

compact=True (new)

true


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

@nineteendo
Copy link
Contributor

Wouldn't indent=None like json.dumps() be more flexible?

@Wulian233
Copy link
Contributor Author

Wulian233 commented Oct 28, 2024

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's indent=0:

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

@devdanzin
Copy link
Contributor

Would it make sense to test that when compact=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-storchaka serhiy-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 add indent="\t" instead, this is familiar to uses of the json library.

@Wulian233
Copy link
Contributor Author

Wulian233 commented Oct 30, 2024

I think setting compact=True would be easier to understand the purpose, and pprint 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 and indent=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, and indent="\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 for pprint() formats the elements in a grid layout. "compact" is width=sys.maxsize.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants