struct problem

Paul Stillwell paul at polariscomm.com
Thu May 27 18:54:51 EDT 1999


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