Best way to split up lines - RE: About the 79 character linerecommendation

John Machin sjmachin at lexicon.net
Thu Dec 7 15:17:09 EST 2006


Roy Smith wrote:
> In article <1165519627.247663.165610 at 73g2000cwn.googlegroups.com>,
>  "John Machin" <sjmachin at lexicon.net> wrote:
>
> > Roy Smith wrote:
> >
> > > It would be nice if struct.unpack() had a way to specify unpacking repeated
> > > items as a list, ie:
> > >
> > >    data = struct.unpack ("! H 4(B) H 2B 12(B) 6(B) H I", strMessage)
> > >    (top,
> > >     ip,
> > >     messageCounter,
> > >     ackRequired,
> > >     dataType,
> > >     utc,
> > >     st,
> > >     numberOfLables,
> > >     dataWord) = data
> > >
> > > and you'd end up with ip, utc, and st being lists.
> >
> > :-)
> > Extension: if you used [] in the format string, the results would be
> > tuples.
> > :-)
>
> I see your point.  Actually, I think you want to force the sequences to be
> lists (regardless of what syntax we end up with), on the theory that tuples
> are for heterogeneous sequences and lists are for homogeneous ones.

And array.arrays are for sequences that are even more homogeneous  :-)
However, after reflection I'd go for lists on practical grounds,
because they're mutable and tuples aren't -- often one wants to start
fiddling with the input.

>  As for
> the parens, I was thinking fortran-style format specifiers, which may or
> may not be the best model for a modern language :-)

Yes, please don't perpetuate 10HANTIQUATED concepts :-)

>
> > >  Hmmm, maybe that's
> > > worth a PEP?
> >
> > Great minds think more-or-less alike :-)
>
> I was in the process of writing one up when I saw your earlier post.  I'll
> mail you a draft when I've got it done.

Great. Looking forward to it.

Cheers,
John




More information about the Python-list mailing list