Re: `to_file()` method for strings
[Posted April 6, 2016 by jake]
From: |
| Chris Barker <chris.barker-32lpuo7BZBA-AT-public.gmane.org> |
To: |
| Andrew Barnert <abarnert-/E1597aS9LQAvxtiuMwx3w-AT-public.gmane.org> |
Subject: |
| Re: `to_file()` method for strings |
Date: |
| Thu, 24 Mar 2016 15:07:30 -0700 |
Message-ID: |
| <CALGmxEJM7VC2CfNY0_UmDCSPpjr1bGXVef6HHo1rX-xuNpfeJQ@mail.gmail.com> |
Cc: |
| Nick Eubank <nickeubank-Re5JQEeQqe8AvxtiuMwx3w-AT-public.gmane.org>, python-ideas <python-ideas-+ZN9ApsXKcEdnm+yROfE0A-AT-public.gmane.org> |
> It is a rare situation when you would want to write just a single string
> to a file.
>
>
> I do it all the time in other languages when dealing with smallish files.
> Python's very nice file-object concept, slant toward iterator-based
> processing, and amazingly consistent ecosystem means that the same issues
> don't apply, so I'd rarely do the same thing.
>
also, Python's strings are immutable, so we really don't want to encourage
people to build up a big string in memory anyway.
and what's wrong with:
open(a_path, 'w').write(the_string)
short, simple one-liner.
OK, non cPython garbage collection may leave that file open and dangling,
but we're talking the quicky scripting data analysis type user -- the
script will terminate soon enough.
BTW, numpy does offer one stop ways to save and load arrays to a file,
binary or text -- and that's a lot more useful than a simple string.
especially the reading.
oh, and for reading:
string = open(path).read()
I really don't get the point of all this.
-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-32lpuo7BZBA@public.gmane.org
_______________________________________________
Python-ideas mailing list
Python-ideas-+ZN9ApsXKcEdnm+yROfE0A@public.gmane.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/