Question about struct.unpack

Eric Jacoboni jaco at neottia.net
Wed Feb 22 09:15:28 EST 2006


Hi,

To experiment with unpacking, i've written a little C code which
stores one record in a file. Then, i try to reread this file to unpack
the record.

Here's the struct of a record:

typedef struct {
      char nom[30];
      double taille;
      int age;
      char plop;
  } enreg_t;

The whole size, as given by sizeof() is 48, due to byte alignment.

I was first thinking that "32sdic" would make the job, but calcsize()
reports only 45 for this format. So, without knowing what, i've tried
"32sdicxxx" to reach the 48 expected... Now it works...

The same file, re-read with a Ruby script needs a
str.unpack("Z32dIc").

So, i don't know why i need to pad the format string in Python. Any
clue?

BTW: how to get rid of all this stuff after the \0 in the first field
in Python? (Ruby has Z and A, but it seems that the Python 's'
specifier is like 'A' and there is no 'Z' equivalent)
-- 
Eric Jacoboni, ne il y a 1444057108 secondes



More information about the Python-list mailing list