Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #39748
| References | (9 earlier) <5129F8C4.4080307@hastings.org> <CAPTjJmq+imANaad7roL_Vfdn02qLVmYLgLkMfcPJbaNVfXtOKA@mail.gmail.com> <512A20A3.1020006@pearwood.info> <CAPTjJmoSwpQzq8WfH+LyNvjaYf81T0hc8nukJmjuC7WCe2qyQQ@mail.gmail.com> <20130224084453.012d9e93@bigbox.christie.dr> |
|---|---|
| Date | 2013-02-25 01:53 +1100 |
| Subject | Re: [Python-ideas] iterable.__unpack__ method |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2407.1361717615.2939.python-list@python.org> (permalink) |
On Mon, Feb 25, 2013 at 1:44 AM, Tim Chase <python.list@tim.thechases.com> wrote: > On 2013-02-25 01:19, Chris Angelico wrote: >> >>> command, subcommand = next(iterargs), next(iterargs) >> >> >> >> >> >> Err.... is there a language guarantee of the order of evaluation >> >> in a tuple, or is this just a "CPython happens to evaluate >> >> independent expressions left-to-right"? This is totally broken >> >> if the next() calls could be done in either order. >> > >> > It's a language guarantee. >> > >> > http://docs.python.org/2/reference/expressions.html#evaluation-order >> >> Ah, so it is. My bad, sorry! In that case, sure, this works. It >> still violates DRY though, naming the iterable twice and relying on >> the reader noticing that that means "take two off this one". But >> that's a much weaker concern. > > Your DRY/readability concern might then be addressed by writing it as > > from itertools import islice > # ... > command, subcommand = islice(iterargs, 2) > > (sorry if this was already addressed in the python-ideas@ thread, > since I'm not subscribed there and it looks like discussion migrated > to python-list@). Blargh, it didn't migrate, I just posted to the wrong list courtesy of a typo. Sorry. ChrisA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: [Python-ideas] iterable.__unpack__ method Chris Angelico <rosuav@gmail.com> - 2013-02-25 01:53 +1100
csiph-web