Newbie Q: (NumPy) how to write an array in a file ?

Alex Martelli aleaxit at yahoo.com
Tue Oct 10 12:06:39 EDT 2000


"Nicolas Decoster" <Nicolas.Decoster at Noveltis.fr> wrote in message
news:39E33793.ADEDAAEC at Noveltis.fr...
> Hi !
>
> First, I must say that it is my first steps in Python and NumPy.
>
> I want to write an array in a file in binary format. Is there something
> as simple and as _fast_ as 'fwrite' from C ?
>
> I don't find anything like that in the documentation. I need something
> that is portable, so I think that pickle will not work.

"binary format" is *NOT* portable.  If you write binary data on a
big-endian machine, you can't just transparently re-read it on a
little-endian machine -- it's even worse for floating-point data
in different formats!

pickle, on the other hand, IS portable between machines (and fast,
in the cPickle version).  Thus, it seems it's what you should use.

If, by "portable", you mean you want to read the data back from
the file in more than one language, not just Python, then the
issues are different, of course.  But for the common meaning of
"portable" ("works transparently on different machines"), pickle
is most likely best.


Alex






More information about the Python-list mailing list