Endianness conversion

Dan Sommers me at privacy.net
Sat Feb 24 11:00:11 EST 2007


On Sat, 24 Feb 2007 15:39:53 +0000, Toby wrote:

> As part of a program I'm writing, I need to save to disk big amounts of
> data (hundreds of MB, in 8kB chunks) swapping every couple of bytes.  
> 
> I obviously cannot do it in a Python loop.
> 
> Is there a function I could use in the standard library, or do I have to
> write my own C extension?

You could try the struct module.  If your input comes in fixed sized
chunks, just call struct.unpack and struct.pack once per chunk.

HTH,
Dan

-- 
Dan Sommers
<http://www.tombstonezero.net/dan/>
Atoms are not things. -- Werner Heisenberg.




More information about the Python-list mailing list