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.write_text should include a newline argument #67894
Comments
The new pathlib.Path [read|write]_[binary|text] methods will be very useful, one thing I miss badly is the newline argument for write_text. In some cases text files need a specific line ending (independent from the platform the code is being executed on.) In my mind this is analogous to passing an explicit encoding argument. Of course, one can always use built-in open for this scenario. It would be a nice addition anyway :) |
It seems a similar API was suggested in the initial stages at https://bugs.python.org/issue20218#msg209017 . But looking at the reference library in the comment https://github.com/jaraco/path.py I think it's more about converting newlines in the given text with respect to the platform instead of adding one at the end. Thanks |
For the newline parameter, what is the expected behaviour? To work as newline from io.open() which supports only so called "legal" newlines which are: None, '', '\n', '\r', and '\r\n', or to allow users use any sequence as newline hence do replacing before passing text to io.open()? |
It should work exactly as the newline argument of open(). Anything else would be surprising. |
CLA signed now and PR is ready :) |
Thank you |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: