Is there a more elegant way to do this?
peter at engcorp.com
Tue Jun 29 06:33:40 CEST 2004
> Peter Hansen <peter at engcorp.com> wrote in message news:<OYydnadytZWWhn3dRVn-ug at powergate.ca>...
>> args = ('Iid Iparent Inumber ix iy iz Bred Bgreen Bblue '
>> 'Hsize Hrotate Htranslucency')
>> lst = zip(*[(x,x[1:]) for x in s.split()])
>> return struct.pack('<' + ''.join(lst),
>> *[getattr(self, n) for n in lst])
> You scary c-like-code-creator, you. :-O
More like Perl, I think, which packs all the unreadability of C
into one tenth the space.
Actually, I thought someone would comment on the emergent
Hungarianesque notation in the above... I think if I
were doing this for real (and I might well if I had the
need), I'd use a decent separator to make the args string
more readable, maybe just 'I-id I-parent I-robot...' or
something. That makes the (x, x[1:]) turn into the
somewhat cleaner x.split('-').
Another actually: zip I find just plain incomprehensible,
but it sure comes in handy from time to time. I can't
seem to fit it in my brain though, and constantly resort
to the interactive prompt to figure out how to use it.
More information about the Python-list