On Jun 13, 6:22 pm, Brian Quinlan <br...@sweetapp.com> wrote: > MRAB wrote: > > Brian Quinlan wrote: > >> kj wrote: > >>> In <slrnh37t2p.63e.n...@irishsea.home.craig-wood.com> Nick Craig-Wood > >>> <n...@craig-wood.com> writes: > > >>>> However I can't think of the last time I wanted to do this - array > >>>> elements having individual purposes are usually a sign that you should > >>>> be using a different data structure. > > >>> In the case I was working with, was a stand-in for the value returned > >>> by some_match.groups(). The match comes from a standard regexp > >>> defined elsewhere and that captures more groups than I need. (This > >>> regexp is applied to every line of a log file.) > > >>> kj > > >> The common idiom for this sort of thing is: > > >> _, _, _, val1, _, _, _, val2, ..., val3 = some_match.groups() > > > Alternatively: > > > val1, val2, val3 = some_match.group(4, 8, something) > > Actually, now that I think about it, naming the groups seems like it > would make this code a lot less brittle.
I was about to suggest that too, but it sounds like the OP has little or no control, in this case, over the RE itself. Another thing I would suggest is using the (?:) syntax--it allows creating a syntactic group that isn't returned in the list of match groups. -- http://mail.python.org/mailman/listinfo/python-list