Improved struct module
Just van Rossum
just at letterror.com
Thu Oct 14 04:21:54 EDT 1999
At 12:25 AM -0400 10/14/99, Tim Peters wrote:
>[comparing Robin Boerdijk's xstruct C extension module
> http://www.sis.nl/python/xstruct/xstruct.html
> with Just van Rossum's sstruct Python module
> http://starship.python.net/crew/just/code/sstruct.py
>]
>> So far, I have only documented up to the point that I thought that people
>> who need to interact intimately with C structs from Python (and have been
>> struggling with struct.pack and struct.unpack to do that) would get
>> enthousiastic about this new module.
Hm, that was largely my motivation, too... The lack of interest in
sstruct.py proved to me that very few people work a lot with C structs.
Unfortunately I wasn't so lucky myself.
>Curiously enough, I hardly ever muck with C structs. I too would like to
>hear from people who do!
I developed sstruct.py mainly because I needed to be able to read and write
an existing binary file format (TTF files) which uses a lot of C structs. I
found myself doing lots of stuff like:
(self.foo, self.bar, self.zazoo, self.blarg =
struct.unpack(format, data[:struct.calcsize(format)]))
and
data = struct.pack(format, self.foo, self.bar, self.zazoo, self.blarg)
which gets very tedious when the number of struct elements is large. But I
also wanted my struct wrapper to work with some existing classes, so a
solution which would just work with class instances and/or dicts seemed
most straightforward to me. Hm, actually, it still does: for my purposes it
would be undesirable to have a special struct object.
>I only jumped in here because I thought you had
>written a very interesting module, and your announcement was followed by
>days of silence. You may not like the approach I've taken here, but it has
>gotten the module some much-needed publicity <wink>.
Which goes for sstruct.py, too, so thank you very much...
Just
More information about the Python-list
mailing list