[Python-ideas] `to_file()` method for strings
Chris Barker
chris.barker at noaa.gov
Mon Mar 28 12:30:56 EDT 2016
On Mon, Mar 28, 2016 at 9:23 AM, Ethan Furman <ethan at stoneleaf.us> wrote:
> '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.
I'm coming around to this actually -- not because it's easier to grok than:
data = open('some_file').read()
but because it could be an atomic operation, and close the file properly.
and Is easier to grok than:
with open('some_file') as infile:
data = infile.read()
and heck, it would even keep the door open to being made a built-in in the
future.
Maybe it's time to hear from the OP on this one -- after all, most of us in
the discussion are already really familiar with the options!
-CHB
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160328/f0fc3cff/attachment.html>
More information about the Python-ideas
mailing list