struct problem

Paul Stillwell paul at polariscomm.com
Thu May 27 20:19:16 EDT 1999


Never mind...  I realized that the file size was 0 on the file I was trying
to open. :p

Paul Stillwell wrote in message ...
>I'm not sure why the following code doesn't work.  I am reading a file and
>want to skip over the first 2 bytes of the file and read the next 2 bytes.
>So, I am doing this:
>
>        from struct import *
>
>        HeaderFormat = '2x2B'
>        HeaderLength = calcsize(HeaderFormat)
>        File = open('d:\starview', 'rb')
>        Header = File.read(HeaderLength)
>        (NumDomains, Version) = unpack(HeaderFormat, Header)
>
>but when I run this code I get:
>
>    (NumDomains, Version) = unpack(HeaderFormat, Header)
>error: unpack str size does not match format
>
>So, what am I doing wrong?  I can read the first 2 bytes into don't care
>variables, but why should I have to?  I would think the pad byte format
>would skip the first 2 bytes and just return the 2 bytes I am interested
in.
>
>I am running Python 1.5.2 on NT 4.
>
>Thanks for any help!
>
>Paul
>paul at polariscomm.com
>
>
>
>






More information about the Python-list mailing list