[New-bugs-announce] [issue20218] Add `pathlib.Path.write` and `pathlib.Path.read`
Ram Rachum
report at bugs.python.org
Fri Jan 10 20:04:53 CET 2014
New submission from Ram Rachum:
I'd really like to have methods `pathlib.Path.write` and `pathlib.Path.read`. Untested implementation:
def read(self, binary=False):
with self.open('br' is binary else 'r') as file:
return file.read()
def write(self, data. binary=False):
with self.open('bw' is binary else 'w') as file:
file.write(data)
This will be super useful to me. Many files actions are one liners like that, and avoiding putting the `with` clause in user code would be wonderful.
Antoine suggests that `binary` shouldn't be an argument, that there should be separate methods for reading/writing text and binary contents, and that the text one would require passing in encoding and other parameters. I'll be happy to add these to the implementation and create a patch, once people can define which parameters should be used.
----------
components: Library (Lib)
messages: 207874
nosy: cool-RR
priority: normal
severity: normal
status: open
title: Add `pathlib.Path.write` and `pathlib.Path.read`
type: enhancement
versions: Python 3.4, Python 3.5
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20218>
_______________________________________
More information about the New-bugs-announce
mailing list