Reading/writing binary data.
Grant Edwards
grante at visi.com
Mon Apr 8 13:55:38 EDT 2002
In article <mailman.1018285938.26500.python-list at python.org>, Jeff Smith wrote:
>> 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.
> 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.
The struct module also allows you to convert between binary and
"internal" formats.
--
Grant Edwards grante Yow! The Korean War must
at have been fun.
visi.com
More information about the Python-list
mailing list