Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #105034 > unrolled thread

Re: empty clause of for loops

Started by"Sven R. Kunze" <srkunze@mail.de>
First post2016-03-16 15:29 +0100
Last post2016-03-16 15:29 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: empty clause of for loops "Sven R. Kunze" <srkunze@mail.de> - 2016-03-16 15:29 +0100

#105034 — Re: empty clause of for loops

From"Sven R. Kunze" <srkunze@mail.de>
Date2016-03-16 15:29 +0100
SubjectRe: empty clause of for loops
Message-ID<mailman.209.1458138589.12893.python-list@python.org>
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.


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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web