Binary file output using python

Peter Otten __peter__ at web.de
Wed Apr 18 02:21:31 EDT 2007


Chi Yin Cheung wrote:

> Is there a way in python to output binary files? I need to python to
> write out a stream of 5 million floating point numbers, separated by
> some separator, but it seems that all python supports natively is string
> information output, which is extremely space inefficient.
> 
> I'd tried using the pickle module, but it crashed whenever I tried using
> it due to the large amount of data involved.

A minimalistic alternative is array.tofile()/fromfile(), but pickle should
handle a list, say, of 5 million floating point numbers just fine. What
exactly are you doing to provoke a crash, and what does it look like?
Please give minimal code and the traceback.

Peter



More information about the Python-list mailing list