with open('data', 'wb') as f:
    a.tofile(f)
b = array.array('h')
with open('data', 'rb') as f:
    b.fromfile(f, 10)
if sys.byteorder == 'little':
    b.byteswap()
How to read/write binary 16-bit data in Python 2.x?