<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><span><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra">It is a rare situation when you would want to write just a single string to a file.</div></div></div></blockquote><div><br></div></span><div>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.</div></div></blockquote><div><br></div><div>also, Python's strings are immutable, so we really don't want to encourage people to build up a big string in memory anyway.</div><div><br></div><div>and what's wrong with:</div><div><br></div><div>open(a_path, 'w').write(the_string)</div><div><br></div><div>short, simple one-liner.</div><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>oh, and for reading:</div><div><br></div><div>string = open(path).read()</div><div><br></div><div>I really don't get the point of all this.</div><div><br></div><div>-CHB</div><div><br></div></div><div><br></div>-- <br><div><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R            <a href="tel:%28206%29%20526-6959" value="+12065266959" target="_blank">(206) 526-6959</a>   voice<br>7600 Sand Point Way NE   <a href="tel:%28206%29%20526-6329" value="+12065266329" target="_blank">(206) 526-6329</a>   fax<br>Seattle, WA  98115       <a href="tel:%28206%29%20526-6317" value="+12065266317" target="_blank">(206) 526-6317</a>   main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a></div>
</div></div>