Re: Endianness conversion

2007-02-25 Thread Dan Sommers
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 ):

Re: Endianness conversion

2007-02-24 Thread Gabriel Genellina
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

Re: Endianness conversion

2007-02-24 Thread Toby
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

Re: Endianness conversion

2007-02-24 Thread Daniel Harding
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

Re: Endianness conversion

2007-02-24 Thread Toby
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

Re: Endianness conversion

2007-02-24 Thread Dan Sommers
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