How to read an integer value from a binary file?

Olivier Elbaz olivier.elbaz at gmail.com
Tue May 3 14:28:37 EDT 2005


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 <jepler at unpythonic.net> wrote:
> 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
> 
> 
>



More information about the Python-list mailing list