Best way to split up lines - RE: About the 79 character linerecommendation
John Machin
sjmachin at lexicon.net
Thu Dec 7 14:27:07 EST 2006
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.
:-)
> Hmmm, maybe that's
> worth a PEP?
Great minds think more-or-less alike :-)
All we need now is for the populace to vote on "least fugly syntax".
Yours has the advantage over mine that it would handle (say) 10(4s)
*if* anybody ever wanted to do that, but the ")" is a redundant
nuisance.
Mine could be changed so that the "/" is between the count and the
format code, so that 10/4s would work ... hmmm there are actually 3
different numbers: an overall repeat count, a tuple/list length, and a
field width. The current syntax uses the one number as a field width
for "s" and as a repeat count for other format codes. Ugh.
BTW the only reason I picked "/" was it doesn't need the Shift key :-)
Cheers,
John
More information about the Python-list
mailing list