Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.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; 'python,': 0.02; 'operator': 0.03; 'none:': 0.05; 'differently': 0.07; 'expressions': 0.07; 'puts': 0.07; 'python': 0.09; 'behave': 0.09; 'subject:while': 0.09; 'language': 0.14; 'sat,': 0.15; 'backward': 0.16; 'expression.': 0.16; 'foo()': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'oct': 0.16; 'operator.': 0.16; 'personally,': 0.16; 'subject:expression': 0.16; 'syntax.': 0.16; 'ternary': 0.16; 'wrote:': 0.17; 'exists': 0.17; 'variable': 0.20; 'do.': 0.21; 'received:209.85.214.174': 0.21; 'assignment': 0.22; 'header:In-Reply-To:1': 0.25; '(which': 0.26; 'am,': 0.27; 'convention': 0.27; 'message-id:@mail.gmail.com': 0.27; 'skip:( 20': 0.28; 'chris': 0.28; 'comparison': 0.29; 'end,': 0.29; 'statements': 0.29; 'unlikely': 0.29; "i'm": 0.29; 'fri,': 0.30; 'print': 0.32; 'to:addr:python-list': 0.33; 'everyone': 0.33; 'received:google.com': 0.34; 'wrong': 0.34; 'compared': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'but': 0.36; 'should': 0.36; 'possible': 0.37; 'itself': 0.37; 'two': 0.37; 'being': 0.37; 'why': 0.37; 'quite': 0.37; 'rather': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'side': 0.61; 'truly': 0.62; 'results': 0.65; '26,': 0.65; 'bar:': 0.84; 'confusing': 0.84; 'enhancement.': 0.84; 'subtly': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=SJXGKBcnnXK+4DckhGR/39P3dSh4YQohkCZPLqZE4lg=; b=S+v5MxcYlrjH6bAdCfVTnTuy2mOSHMsp4ClSnplHXA+JY7tOqgP/ZbSig/n5BYhKgD E+OS0qwzGsBh57WX1nphm608Ufs8Aofuo5YZU/Wv72DbZ9Gy77DLELETpyBPl9AA06MH dpyt8etDn3JXdHQwp8Km/ql0yUJifUpIjYIRvagvsnxi1rESojw2z2p8lwvCNIkOa1x+ /jJy80+l5H7TPbc28MlCvemf85J9YQg7khXea4SrLG81GNQK1W3Rzt30qBZXXGNJxV8N sQmATTJjd4KU/g9JwNQSgJGJ5aKEtsG7Guz7XogzobQ4c4FHZX/n7huOXMh0zTmGd+oX 5kYQ== MIME-Version: 1.0 In-Reply-To: References: <50886398.5050301@tim.thechases.com> <7x7gqf1na2.fsf@ruckus.brouhaha.com> <7x7gqdzs1i.fsf@ruckus.brouhaha.com> Date: Sat, 27 Oct 2012 11:42:25 +1100 Subject: Re: while expression feature proposal From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351298548 news.xs4all.nl 6860 [2001:888:2000:d::a6]:57258 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32258 On Sat, Oct 27, 2012 at 10:19 AM, Devin Jeanpierre wrote: > On Fri, Oct 26, 2012 at 2:23 AM, Chris Angelico wrote: >> while (client.spop("profile_ids") as profile_id) is not None: >> print profile_id >> >> Why is everyone skirting around C-style assignment expressions as >> though they're simultaneously anathema and the goal? :) > > Why should these two statements behave differently? :( > > with foo() as bar: bar.baz() > with (foo() as bar): bar.baz() > > I don't understand why everyone is so attached to this "as" syntax. > It's confusing because it behaves subtly differently than how it works > in "with", and it puts the variable on the wrong side of the > assignment operator. > > (I've always been partial to ":=", personally.) I'm not attached to "as", myself. It puts the variable at the wrong end, and feels backward compared to a convention that exists elsewhere in the language (regular variable assignment). This is a much stronger backwardness issue than the Python ternary operator (which is only backward in comparison to other languages). Personally, I'm quite happy with assignment itself being an expression. But since that's unlikely to be directly accepted in Python, I would be looking for something as general as possible - something that can truly be used _anywhere_ - rather than a specific while-statement enhancement. Capturing partial expression results is an extremely convenient thing to do. ChrisA