[issue20218] Add `pathlib.Path.write` and `pathlib.Path.read`
Christopher Welborn
report at bugs.python.org
Tue Jan 21 03:16:46 CET 2014
Christopher Welborn added the comment:
Isn't this something you could do yourself?
import pathlib
def pathread(self, binary=False):
with self.open('br'if binary else 'r') as fread:
return fread.read()
def pathwrite(self, data, mode='w'):
with self.open(mode) as fwrite:
fwrite.write(data)
pathlib.Path.read = pathread
pathlib.Path.write = pathwrite
p = pathlib.Path('/mydir/example.txt')
p.read()
# 'Content from path.\n'
p.write('I am appending.\n', mode='a')
p.read()
# 'Content from path.\nI am appending.\n'
...and what about:
"There should be one-- and preferably only one --obvious way to do it."
----------
nosy: +cjwelborn
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20218>
_______________________________________
More information about the Python-bugs-list
mailing list