Unpacking byte strings from a file of unknown size

Scott David Daniels Scott.Daniels at Acm.Org
Tue Oct 28 12:10:03 EDT 2008


Mark wrote:
> Thanks I tested your solution and that works.
> 
> One of the things that didn't work was
> for chunk in myfile.read(10):
>     info1, info2, info3 = struct.unpack('<IIH', chunk)
> 
> It gets an error saying unpack requires a string of length 10, which I
> thought chunk would be after the read(10).  I'm still a little
> confused as to why.

this code python interprets as:

     data = myfile.read(10)
     for chunk in data:
         <and here chunk is a single-character string>.


--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list