[Python-ideas] `to_file()` method for strings
Ethan Furman
ethan at stoneleaf.us
Mon Mar 28 12:23:14 EDT 2016
On 03/28/2016 08:20 AM, Chris Barker - NOAA Federal wrote:
> 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').
>
> Nick's observation about the mental model may be correct ( though I
> don't think so, frankly), but if it is, then this isn't any better
> than:
>
> open("some_path", 'w').write(string)
>
> " I need to open a file to write something to disk" isn't any harder
> to grok than "I need the io module to write something to disk".
The benefit here is that the `io` module is a natural place to put a
file `read` and `write` function, and they don't need to be built-in.
--
~Ethan~
More information about the Python-ideas
mailing list