Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'say,': 0.05; 'false.': 0.07; 'none):': 0.07; 'python': 0.09; 'arguments,': 0.09; 'commonly': 0.09; 'loop.': 0.09; 'subject:while': 0.09; 'cc:addr :python-list': 0.10; 'thread': 0.11; 'value.': 0.15; '"none"': 0.16; '"while': 0.16; 'boolean': 0.16; 'expr': 0.16; 'iterated': 0.16; 'loops': 0.16; 'oct': 0.16; 'popping': 0.16; 'subject:expression': 0.16; 'true:': 0.16; 'wrote:': 0.17; 'received:209.85.216.46': 0.21; 'cc:2**0': 0.23; "i've": 0.23; 'seems': 0.23; 'cc:no real name:2**0': 0.24; 'pass': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'topic': 0.27; 'set.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'run': 0.28; 'dan': 0.29; 'case,': 0.29; 'e.g.': 0.30; 'fri,': 0.30; '(and': 0.32; 'print': 0.32; 'message.': 0.33; 'says': 0.33; 'changed': 0.34; 'received:google.com': 0.34; 'received:209.85': 0.35; 'client': 0.36; 'should': 0.36; 'being': 0.37; 'rather': 0.37; 'received:209': 0.37; 'received:209.85.216': 0.37; 'subject:: ': 0.38; 'header:Received:5': 0.40; 'more': 0.63; 'to,': 0.65; '26,': 0.65; 'fact,': 0.69; 'write:': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=KD3WRVCrZByNTX3T35V9iAckOA3hyoyaHyl3zn8Rirc=; b=zL/kngRnCtOKBANE2mB/+YabSvh4+xan+AxX9NmT8vlSjeivwwwL5r6H/9P5QKCV2/ 0j7rnuF5ZLk+QzALbij8HSl4pNIgcbFuMa3rWq2WtUPFwC8Fsgd5Mwkkc1hBrNk/8/ur ROmd2wsAPzcmRKLK81v7UC11T25lZhzxJzYrsOFsNO9oUdpuvZGtYmD62pr0S+82rF6H UfSJTbIapzjK6NDvRN0EkfEjMHxi4Ij3soyURLvH3RKYAqSDl4k8TQJFGKdMSrAB/nuS 3ia8jQg/So9yqHO3CImWBlXcI31MH1QK2znEzMTmgp0nFPXT1OkL0G9vIpS/ucBpK07Y 4EdQ== MIME-Version: 1.0 In-Reply-To: References: <50886398.5050301@tim.thechases.com> <7x7gqf1na2.fsf@ruckus.brouhaha.com> From: Devin Jeanpierre Date: Fri, 26 Oct 2012 19:12:17 -0400 Subject: Re: while expression feature proposal To: Dan Loewenherz Content-Type: text/plain; charset=UTF-8 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351293180 news.xs4all.nl 6864 [2001:888:2000:d::a6]:60767 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32242 On Fri, Oct 26, 2012 at 1:12 AM, Dan Loewenherz wrote: > It seems the topic of this thread has changed drastically from the original message. > > 1) "while EXPR as VAR" in no way says that EXPR must be a boolean value. In fact, a use case I've run into commonly in web development is popping from a redis set. E.g. > > client = StrictRedis() > while True: > profile_id = client.spop("profile_ids") > if not profile_id: > break > print profile_id > > In this case, profile_id is "None" when the loop breaks. It would be much more straightforward (and more Pythonic, IMO), to write: > > client = StrictRedis() > while client.spop("profile_ids") as profile_id: > print profile_id For loops are pythonic. You can do this in Python today: client = StrictRedis() for profile_id in iter(lambda: client.spop("profile_ids"), None): pass I would like a better iter(), rather than a better while loop. It is irritating to pass in functions that take arguments, and it is impossible to, say, pass in functions that should stop being iterated over when they return _either_ a None or a, say, False. -- Devin