Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Sven R. Kunze" Newsgroups: comp.lang.python Subject: Re: empty clause of for loops Date: Wed, 16 Mar 2016 15:29:46 +0100 Lines: 35 Message-ID: References: <56E93413.6090108@mail.de> <56E94EB9.9050507@mail.de> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de KIq50lJPKhYkGPJ1I2yMlQRD90N8wmnVASQ+A5Eau8Lw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.060 X-Spam-Evidence: '*H*': 0.88; '*S*': 0.00; 'else:': 0.03; 'considered.': 0.09; 'throw': 0.09; 'syntax': 0.13; 'clause,': 0.16; 'clause.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'stdlib.': 0.16; 'syntactical': 0.16; 'wrote:': 0.16; ';-)': 0.18; 'exceptions': 0.22; 'function,': 0.22; '(or': 0.23; 'header :In-Reply-To:1': 0.24; 'feature': 0.24; 'room': 0.27; 'least': 0.27; 'question': 0.27; 'cool': 0.27; 'function': 0.28; 'this.': 0.28; "i'd": 0.31; 'implement': 0.32; 'language.': 0.32; 'useful': 0.33; 'received:10.0': 0.34; 'best,': 0.35; 'could': 0.35; 'quite': 0.35; 'something': 0.35; 'item': 0.35; 'should': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'requirement': 0.37; 'thought': 0.37; 'why': 0.39; 'easily': 0.39; 'rather': 0.39; 'well.': 0.40; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'your': 0.60; 'charset:windows-1252': 0.62; 'personal': 0.63; 'benefit': 0.66; 'choose': 0.68; 'answer:': 0.84; 'asked.': 0.84; 'conceived': 0.84; 'disappointed': 0.84; 'otten': 0.84; 'glad': 0.87; 'severe': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mail.de; s=mail201212; t=1458138586; bh=WetDeV7+aCtZYIWPRTkBx7Rmic4qNpej8ihcXDSzlcI=; h=Subject:To:References:From:Date:In-Reply-To:From; b=DkNRFcPHG1VCVuJJChr5N2t1CpVz2IlQTwQBeO1boiKJqFLMQi4SxNT4H68lspeMf YtU3Jt0L5yv+oaZ0Gw+ZFuxqoTC6Pks5Wf3eo4k+rEYfOsUHZu3NejAKIcTUJawXay xEa0tBnvgIdCapb957jUA4F1W4YeXhqmgRv/L8Kc= In-Reply-To: X-purgate: clean X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate-type: clean X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate: clean X-purgate-size: 1192 X-purgate-ID: 154282::1458138586-00003BBD-6DB98C49/0/0 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105034 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