mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
bpo-23706: Add newline parameter to pathlib.Path.write_text (GH-22420) (GH-22420)
* Add _newline_ parameter to `pathlib.Path.write_text()` * Update documentation of `pathlib.Path.write_text()` * Add test case for `pathlib.Path.write_text()` calls with _newline_ parameter passed Automerge-Triggered-By: GH:methane
This commit is contained in:
parent
25492a5b59
commit
5f22741340
4 changed files with 27 additions and 3 deletions
|
@ -1264,14 +1264,14 @@ class Path(PurePath):
|
|||
with self.open(mode='wb') as f:
|
||||
return f.write(view)
|
||||
|
||||
def write_text(self, data, encoding=None, errors=None):
|
||||
def write_text(self, data, encoding=None, errors=None, newline=None):
|
||||
"""
|
||||
Open the file in text mode, write to it, and close the file.
|
||||
"""
|
||||
if not isinstance(data, str):
|
||||
raise TypeError('data must be str, not %s' %
|
||||
data.__class__.__name__)
|
||||
with self.open(mode='w', encoding=encoding, errors=errors) as f:
|
||||
with self.open(mode='w', encoding=encoding, errors=errors, newline=newline) as f:
|
||||
return f.write(data)
|
||||
|
||||
def readlink(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue