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

pathlib.Path.read_text should include a newline argument #110745

Closed
treyhunner opened this issue Oct 11, 2023 · 2 comments
Closed

pathlib.Path.read_text should include a newline argument #110745

treyhunner opened this issue Oct 11, 2023 · 2 comments
Labels
easy topic-pathlib type-feature A feature request or enhancement

Comments

@treyhunner
Copy link
Member

treyhunner commented Oct 11, 2023

Feature or enhancement

Proposal:

Support for a newline argument was added to the write_text method in Python 3.10 (issue #67894).

I've been using this method but I've found a need for a newline method for read_text as well.

Here's the scenario where this would be handy (namely reading and writing the original newlines):

from pathlib import Path

path = Path("my_file.txt")

contents = path.read_text(newline="")

contents = perform_some_operation_on(contents)

path.write_text(contents, newline="")

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

I have not found any prior discussions or mentions of newline argument being supported for read_text outside of the initial pathlib API discussion (#64417 (comment)).

Linked PRs

@treyhunner treyhunner added the type-feature A feature request or enhancement label Oct 11, 2023
@Okabe-Junya
Copy link
Contributor

Thanks for all the great software!

I would like to work on this issue. This is my first contribution to cpython, but I will do my best!

Okabe-Junya added a commit to Okabe-Junya/cpython that referenced this issue Oct 14, 2023
barneygale added a commit that referenced this issue Nov 21, 2023
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Barney Gale <barney.gale@gmail.com>
@barneygale
Copy link
Contributor

Resolved in #110880. Thank you very much @Okabe-Junya!

aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
…thon#110880)

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Barney Gale <barney.gale@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy topic-pathlib type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants