[Python-Dev] proposed struct module format code addition

Guido van Rossum gvanrossum at gmail.com
Sun Oct 3 18:06:47 CEST 2004

> > If you believe this functionality is useful, or even if you think that
> I
> > am full of it, tell us: http://python.org/sf/1023290
> The suggested alternative is adding two functions to binascii that
> parallel the existing hexlify() and unhexlify().

Those functions ought to exist whether or not this RFE is accepted.

Here's the crux I think. Is this used often enough in a context where
(a) the length of the number is fixed (not determined by a count in a
previous field) and (b) preceded or followed by other fixed-length
fields so that it makes sense to use the struct module for parsing or
formatting those other fields?

I have often found that amongst less-experienced programmers there is
a great mystery about the correspondence between the "binary"
representation of numbers (in strings of bytes) and the numeric
objects that Python makes available (int, lont). Often the struct
module is considered the only way to cross this boundary, while in
fact there are many other approaches; often using the built-in
functions ord() or chr() and shifting and masking works just as well,
but you have to think about it the right way.

I apologize for not having read the entire post  before responding; in
case the motivation is already there, that's great, and let it be a
response to Raymond. If it is not there, I like Raymond's proposal

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list