Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #105039
| From | "Sven R. Kunze" <srkunze@mail.de> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: empty clause of for loops |
| Date | 2016-03-16 15:39 +0100 |
| Message-ID | <mailman.212.1458139185.12893.python-list@python.org> (permalink) |
| References | <56E93413.6090108@mail.de> <ncbdk4$h9u$1@ger.gmane.org> <56E94EB9.9050507@mail.de> <ncbl8p$hq6$1@ger.gmane.org> <56E96DDA.30008@mail.de> |
On 16.03.2016 15:29, Sven R. Kunze wrote: > On 16.03.2016 13:57, Peter Otten wrote: >> >> I'd put that the other way round: syntactical support for every pattern >> would make for a rather unwieldy language. You have to choose >> carefully, and >> this requirement could easily be fulfilled by a function, first in your >> personal toolbox, then in a public libary, then in the stdlib. >> >> If you don't like exceptions implement (or find) something like >> >> items = peek(items) >> if items.has_more(): >> # at least one item >> for item in items: >> ... >> else: >> # empty >> >> Only if such a function is used a lot or cannot be conceived without >> severe >> shortcumings adding to the syntax should be considered. The >> (hypothetical) >> question you should answer: which current feature would you throw out to >> make room for your cool new addition? > > I am glad you asked. ;-) > > I would re-use the "for-else" for this. [Everything] I thought I could > make use of the "-else" clause, I was disappointed I couldn't. > [everytime] > > I find the addition to for-loop as useful as we already have a quite > complex try-except-else-finally clause. I don't know why for-loops > couldn't benefit from this as well. > > > Best, > Sven
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: empty clause of for loops "Sven R. Kunze" <srkunze@mail.de> - 2016-03-16 15:39 +0100
csiph-web