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

Ethan Furman ethan at stoneleaf.us
Fri Mar 25 14:04:27 EDT 2016


On 03/25/2016 09:57 AM, Zachary Ware wrote:
> On Wed, Mar 23, 2016 at 1:45 AM, Nick Coghlan wrote:

>> 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.
>
> In this vein, what about just adding io.read() and io.write()
> convenience functions that take the same arguments as io.open() (with
> an added 'data' parameter for write()) and do the obvious "open file,
> return file.read_or_write(), close file"?  This doesn't answer the
> atomic write question, but that wasn't in the OP.  The OP's
> 'string'.to_file('some_file') would just be io.write('string',
> 'some_file'), and str.from_file('some_file') would be
> io.read('some_file').  Granted, both functions are 3 lines of Python,
> but they might well be used enough to be worth adding.

+1 (with extra keyword arguments for fun ;)

--
~Ethan~



More information about the Python-ideas mailing list