Re: How to read an integer value from a binary file?

2005-05-03 Thread John Machin
On Tue, 3 May 2005 19:46:17 +0200, Olivier Elbaz <[EMAIL PROTECTED]> wrote: >Hi, > >I read a bmp file (binary file) and I want to extract an integer value >from it (size value). >The whole binary file is read inside a list "all_bmp_file". >I can read the "size" value with the following code: >for

Re: How to read an integer value from a binary file?

2005-05-03 Thread Olivier Elbaz
Hi Jeff, You was right, my problem was coming from the number of items that I gave to the "unpack" method. I was thinking,like an array in C, that slice [2:5] will give 4 items and not 3. Thanks a lot for your help. Olivier On 5/3/05, Jeff Epler <[EMAIL PROTECTED]> wrote: > As your 'for' loop s

Re: How to read an integer value from a binary file?

2005-05-03 Thread Jeff Epler
As your 'for' loop shows, the number of items in the slice [2:5] is only 3, not 4. Maybe you want the slice [2:6] instead. >>> x = "xx\xb6/\0\0" >>> struct.unpack('i', x[2:6]) (12214,) Jeff pgprzSG2OzoK4.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

How to read an integer value from a binary file?

2005-05-03 Thread Olivier Elbaz
Hi, I read a bmp file (binary file) and I want to extract an integer value from it (size value). The whole binary file is read inside a list "all_bmp_file". I can read the "size" value with the following code: for r in all_bmp_file[2:5]: n = struct.unpack('B',r)#B for unsigned char print n R