On Sat, 24 Feb 2007 17:27:12 +, 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 ):
En Sat, 24 Feb 2007 14:27:12 -0300, Toby <[EMAIL PROTECTED]> escribió:
> I ended up writing my own byteswapper in Pyrex:
You can use the byteswap method of arrays:
>>> import array
>>> a = array.array('H', 'ABcd56')
>>> a.tostring()
'ABcd56'
>>> a.byteswap()
>>> a.tostring()
'BAdc65'
--
Gabrie
Daniel Harding wrote:
> Try the using the array module. array objects provide a byteswap
> method which reverses endianness.
Thanks!
Toby
--
http://mail.python.org/mailman/listinfo/python-list
On Feb 24, 9:39 am, Toby <[EMAIL PROTECTED]> 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 lib
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.
I ended up writing my own byteswapper in Pyrex:
def swapbytes(data):
"Swap every
On Sat, 24 Feb 2007 15:39:53 +, 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 li