finding byte order

Scott David Daniels Scott.Daniels at Acm.Org
Fri Dec 3 12:28:11 EST 2004


biner wrote:
 >   I would like to have a test to tell me if the current machine is
 > using big or small endian, this way I could use the array module in
 > the first case and the *slower* struct module on the second. I looked
 > but did not find. Is there a python function to know that?
 >
 > Thanks!

How about sys.byteorder?

At least if you are using array.array, note the "byteswap" method:

     >>> import array
     >>> v = array.array('h',range(8))
     >>> v
     array('h', [0, 1, 2, 3, 4, 5, 6, 7])
     >>> v.byteswap()
     >>> v
     array('h', [0, 256, 512, 768, 1024, 1280, 1536, 1792])

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list