converting from perl: variable sized unpack

Duncan Booth duncan at NOSPAMrcp.co.uk
Mon Jul 16 05:53:08 EDT 2001


quinn at yak.ugcs.caltech.edu (Quinn Dunkan) wrote in
news:slrn9l4esk.885.quinn at yak.ugcs.caltech.edu: 

> Ruby allows * notation:
> 
> a, b, *c = sequence # `c' gets the rest of the sequence
> 
> which is cute, but I don't like it.  Just another random "convenient"
> little trick to remember.  It's not half as useful as the 1.6 * apply
> trick.  Let's go easy on the syntax gimmicks.

The Python equivalent to the Ruby trick really isn't that much longer, and 
to my mind has the advantage of showing more clearly the programmer's 
intent:
   (a, b), c = sequence[:2], sequence[2:]

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?



More information about the Python-list mailing list