[Pythonmac-SIG] reading/writing binary data?

Just van Rossum just@letterror.com
Thu, 21 Jan 1999 01:21:15 +0100


At 3:19 PM -0800 1/20/99, David Ascher wrote:
>On Wed, 20 Jan 1999, Joseph J. Strout wrote:
>
>> or long ints (or even whole lists of ints?) at once.  Could somebody please
>> point out what I'm missing?
>
>My guess would be, the struct module and its unpack() function.

Yeah, and read the docs for special "operators" for endian-ness.


If you're talking about arrays of ints, the array module comes in handy:

import array

a = array.array("h")  # array of signed short ints
a.fromstring("\0\1\0\2")   # two raw shorts
print a

(Or even NumPy, but that might be overkill.)

Just