Changing endian format

Miki Tebeka miki.tebeka at zoran.com
Sun Jan 25 11:55:23 EST 2004


Hell Amit,

> I have a binary file and i need to change the endian format..little to big as 
> well as vice versa..could anyone help me out.
Warning: Not tested!

#!/usr/bin/env python
from sys import argv
from array import array

a = array("H", open(argv[1], "rb").read())
a.byteswap()
open(argv[2], "wb").write(a.tostring())

HTH.
Miki



More information about the Python-list mailing list