[Python-ideas] `to_file()` method for strings

Brett Cannon brett at python.org
Wed Mar 23 12:22:05 EDT 2016


On Tue, 22 Mar 2016 at 23:46 Nick Coghlan <ncoghlan at gmail.com> wrote:

> On 23 March 2016 at 15:44, Nick Eubank <nickeubank at gmail.com> wrote:
> > True -- my feeling is that if we're ok with defaults in a pathlib method,
> > why not put them in a string method?
>
> pathlib is explicitly about filesytem management and manipulation,
> while strings don't inherently have anything to do with filesystems,
> and only a little bit to do with serialisation (via str.encode).
>
> Having some lower level convenience functions in io may make sense
> (specifically io.write_bytes(path, data) and io.write_text(path, data,
> encoding=None, errors=None), but the str builtin definitely isn't the
> right place for the capability.
>

I agree this has nothing to do with `str` or `bytes` directly and should
not be exposed on those types. And if you look at the issue that Victor
linked to, getting a function that behaves consistently for atomic file
operations across OSs is very tough. I think it would be best is follow the
advice Victor gave in the issue he linked to and for someone to make a
library with defaults they think are reasonable for atomic file operations,
put it on PyPI, and get community feedback before trying to add it to the
stdlib.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160323/d6d52626/attachment-0001.html>


More information about the Python-ideas mailing list