On Sat, 24 Feb 2007 17:27:12 +0000, Toby wrote:

> Dan Sommers wrote:
>> You could try the struct module.  If your input comes in fixed sized
>> chunks, just call struct.unpack and struct.pack once per chunk.
> 
> Thanks, but it was a bit awkward to use for big chunks.

def swapper( bytestring ):
    someHs = len( bytestring ) / 2 * "H" # could check for odd-lengths?
    unpackfmt = "<" + someHs
    packfmt = ">" + someHs
    return struct.pack( packfmt, *struct.unpack( unpackfmt, bytestring )

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

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to