This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: pathlib.Path.write_text should include a newline argument
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: THRlWiTi, daniel.ugra, maksvenberv, methane, miss-islington, pitrou, serhiy.storchaka, uranusjr, xtreak
Priority: normal Keywords: easy, patch

Created on 2015-03-19 09:32 by daniel.ugra, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 22420 merged maksvenberv, 2020-09-26 22:21
Messages (7)
msg238498 - (view) Author: Ugra Dániel (daniel.ugra) Date: 2015-03-19 09:32
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 :)
msg326096 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-09-22 16:14
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
msg377575 - (view) Author: Maxim Burov (maksvenberv) * Date: 2020-09-27 17:11
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()?
msg377577 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-09-27 18:09
It should work exactly as the newline argument of open(). Anything else would be surprising.
msg377693 - (view) Author: Maxim Burov (maksvenberv) * Date: 2020-09-30 07:38
CLA signed now and PR is ready :)
msg379180 - (view) Author: miss-islington (miss-islington) Date: 2020-10-21 02:08
New changeset 5f227413400c4dfdba210cc0f8c9305421638bc1 by Максим in branch 'master':
bpo-23706: Add newline parameter to pathlib.Path.write_text (GH-22420) (GH-22420)
https://github.com/python/cpython/commit/5f227413400c4dfdba210cc0f8c9305421638bc1
msg379181 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2020-10-21 02:19
Thank you
History
Date User Action Args
2022-04-11 14:58:14adminsetgithub: 67894
2020-10-21 02:19:28methanesetstatus: open -> closed

nosy: + methane
messages: + msg379181

resolution: fixed
stage: patch review -> resolved
2020-10-21 02:08:27miss-islingtonsetnosy: + miss-islington
messages: + msg379180
2020-09-30 07:38:59maksvenbervsetmessages: + msg377693
2020-09-27 18:09:03serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg377577
2020-09-27 17:11:26maksvenbervsetmessages: + msg377575
2020-09-26 22:21:42maksvenbervsetkeywords: + patch
nosy: + maksvenberv

pull_requests: + pull_request21458
stage: needs patch -> patch review
2020-09-12 08:43:52serhiy.storchakasetkeywords: + easy
stage: needs patch
versions: + Python 3.10, - Python 3.5
2019-11-20 03:10:10uranusjrsetnosy: + uranusjr
2018-10-05 03:46:09THRlWiTisetnosy: + THRlWiTi
2018-09-22 16:14:12xtreaksetnosy: + xtreak
messages: + msg326096
2015-03-19 20:18:59ned.deilysetnosy: + pitrou
2015-03-19 09:32:41daniel.ugracreate