biner wrote:
>   I am using a program that has to read binary data from files coming
> from different machines. The file are always written with big endian.

Diez B. Roggisch wrote:
 [Scott David Daniels wrote]
How about sys.byteorder?
This doesn't help, as he wants to read files from varying endianess - what
the _current_ endianess is doesn't matter here.

But, in fact, he says the files are always big endian. So, code like the following should address his problem. Note I use type 'h' as an example so I can easily read samples.

    import sys, array
    f =open('huge.dat')
    v = array.array('h')   # Or whatever data type
    v.fromfile(f, 4096)
    f.close()
    if sys.byteorder == 'little':
        v.byteswap()

--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to