Reading/writing binary data.
Jeff Smith
smithj at nsidc.org
Mon Apr 8 13:11:24 EDT 2002
On Mon, 8 Apr 2002, Ben Logan wrote:
> Hello,
>
> I've been searching the Python (1.5) docs, but am unable to find any
> functions to read/write binary data from/to a file. Under the "open"
> function I see that you can append a "b" to the mode to specify binary
> mode, but that doesn't help me any.
>
> For example, if I want to take a list of numbers like [64,66,67] and
> write them to a file as binary, how would I do that? I also need to
> be able to control whether the data is written in big endian or little
> endian format.
>
> BTW, I'm running Redhat 7.1 on an Intel processor.
>
> Thanks,
> Ben
>
> --
> Ben Logan: ben at wblogan dot net
> OpenPGP Key KeyID: A1ADD1F0
>
> Overdrawn? But I still have checks left!
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
The array module has everything you need. You can use the tofile and
fromfile methods to read and write binary data, the tolist and fromlist
methods to switch data to/from lists, and the byteswap method for swapping
between big- and little-endian.
Jeff Smith
More information about the Python-list
mailing list