A class for C-like structuures in Python

Alex Martelli alex at magenta.com
Wed Aug 9 18:24:43 EDT 2000


"Kevin Digweed" <Kevin.Digweed at dial.pipex.com> wrote in message
news:399122B2.74B86E4B at dial.pipex.com...
> Alex Martelli wrote:
> > It would also be possible (but this is a matter of performance, and
> > not a very important one) to optimize asBytes, if it's called often,
> > into a single statement:
> >
> >     def asBytes(self):
> >         return apply(struct.pack,[self.fmt]+self.members.values())
>
> Be careful here - {}.values() does not yield a predictably ordered list.

Very good point, and very important -- I *did* say I was having
a truly bad day:-(.  Yes, the order of the members needs to be
kept in a separate sequence, since it's crucial -- a mapping has
no specific order.


Alex






More information about the Python-list mailing list