diff options
author | Максим <maksvenberv@yandex.ru> | 2020-10-21 02:08:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-21 02:08:19 (GMT) |
commit | 5f227413400c4dfdba210cc0f8c9305421638bc1 (patch) | |
tree | 38e93bae801217c8797740e01c68ed3811665eb9 /Lib/pathlib.py | |
parent | 25492a5b59c5b74328278f195540e318ab87674f (diff) | |
download | cpython-5f227413400c4dfdba210cc0f8c9305421638bc1.zip cpython-5f227413400c4dfdba210cc0f8c9305421638bc1.tar.gz cpython-5f227413400c4dfdba210cc0f8c9305421638bc1.tar.bz2 |
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
Diffstat (limited to 'Lib/pathlib.py')
-rw-r--r-- | Lib/pathlib.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py index 147be2f..178c5b9 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -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): |