Binary file output using python

kyosohma at gmail.com kyosohma at gmail.com
Tue Apr 17 14:07:38 EDT 2007


On Apr 17, 12:41 pm, Chi Yin Cheung <c-che... at northwestern.edu> wrote:
> Hi,
> 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.
>
> Thanks for your help!

You can create a binary file by doing something like this:

f = open(r'filename, 'b')
f.write('1,2,3,4,5,6')
f.close()

See also: http://www.devshed.com/c/a/Python/File-Management-in-Python/

Have fun!

Mike




More information about the Python-list mailing list