[Numpy-discussion] savetxt to a string?

Peter numpy-discussion at maubp.freeserve.co.uk
Wed Dec 22 09:33:05 EST 2010

On Wed, Dec 22, 2010 at 1:53 PM, Neal Becker <ndbecker2 at gmail.com> wrote:
> Peter wrote:
>> On Wed, Dec 22, 2010 at 1:08 PM, Neal Becker <ndbecker2 at gmail.com> wrote:
>>> Is the formatting of savetxt available with a string as the destination?
>>> If not, shouldn't this functionality be factored out of savetxt?
>> Have you tried using a StringIO handle?
>> Peter
> Yup.  But wouldn't it be cleaner to factor out this functionality and make
> saving to a file use this?

I doubt it.

I would think from a code point of view no - taking filenames or handles
means you can write everything using handle.write(...) statements, and
send the data to disk (or a StringIO handle) gradually. This scales well
with large data.

If you wanted a single code base to support filenames, handles, or
output as a string I think you'd be forced to build a large string in
memory, and then (if applicable) write it to disk (in one go). This
won't scale well with large data.


More information about the NumPy-Discussion mailing list