Help how do I read `word' variables from a binary file?

David Fuess fuess at att.net
Mon Mar 26 08:01:29 EST 2001


Read the data in recordsize groups like you're doing now, then use
struct.py do decompose the records into Python variables.

Dave

On Mon, 26 Mar 2001 12:57:31 GMT, nomad***@***freemail.absa.co.za
(nomad) wrote:

>Howzit,
>
>I'm having trouble with reading a binary file properly in Python 2.0
>on win32.  I'm stating explicitly that I'm using Win32 as I know that
>you have to state when opening the file that it is for `br' as in
>binary reading (I'm think this is due to intels little-endian
>approach, but I could be wrong).
>
>I can open the file without problems, and I can read from the file
>without a hitch, _BUT_ the trouble comes in that some of the data
>records in the file have fields that would be a double word or even a
>normal word in C++, so in effect the data may be 0x80002310, but
>python reads the data directly from the file, and as such is reading
>hex bytes as (in this example) `10 23 00 80' etc.  I'm sure that there
>must be a simple way to read in data like this, but I can't figure it
>out.
>
>Any help would be greatfully recieved.
>
>TIA.




More information about the Python-list mailing list