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


Groups > comp.lang.python > #63017

Re: Ifs and assignments

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'from:addr:yahoo.co.uk': 0.04; 'syntax': 0.04; 'assignment': 0.07; 'class,': 0.07; 'nicely': 0.07; 'consistency': 0.09; 'inserted': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'language.': 0.14; 'assignments': 0.16; 'c/c++': 0.16; 'ought': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'suggestion.': 0.16; 'language': 0.16; 'wrote:': 0.18; 'appears': 0.22; 'header:User-Agent:1': 0.23; 'source': 0.25; 'suggested': 0.26; 'post': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'point': 0.28; 'testing': 0.29; 'character': 0.29; 'end,': 0.31; 'equality': 0.31; 'gary': 0.31; 'occurs': 0.31; 'post.': 0.31; 'workaround': 0.31; 'another': 0.32; 'style': 0.33; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'whilst': 0.36; 'example,': 0.37; 'follows:': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'that,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'easy': 0.60; 'liked': 0.60; 'john': 0.61; 'further': 0.61; 'our': 0.64; 'different': 0.65; 'here': 0.66; 'between': 0.67; 'advantages': 0.68; 'apart': 0.72; "'with'": 0.84; 'avoids': 0.84; 'sorry.': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: Ifs and assignments
Date Fri, 03 Jan 2014 01:20:51 +0000
References <52C59FF6.5000607@allsup.co> <52C5BD90.9020609@islandtraining.com> <52C5DDA6.5090207@allsup.co> <52C60AF6.8060004@islandtraining.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host host-78-147-28-22.as13285.net
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.2.0
In-Reply-To <52C60AF6.8060004@islandtraining.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4819.1388712057.18130.python-list@python.org> (permalink)
Lines 49
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1388712057 news.xs4all.nl 2837 [2001:888:2000:d::a6]:42529
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:63017

Show key headers only | View raw


On 03/01/2014 00:57, Gary Herron wrote:
> On 01/02/2014 01:44 PM, John Allsup wrote:
>> The point of my original post was that, whilst C's
>>   if( x = 2 ) { do something }
>> and
>>   if( x == 2 ) { do something }
>> are easy to confuse, and a source of bugs, having a construct like
>> follows:
>>
>> if x == 2:
>>     do something # what happens at present
>> if testFunc() as x:
>>     do something with x
>>
>> using the 'as' syntax that appears with 'with' and 'except', would allow
>> for the advantages of C style assignments in conditionals but without
>> the easy confusion, since here the syntax is significantly different
>> between assignment and equality testing (rather than a character apart
>> as happens with C).
>>
>> This occurs further down in my original post (past the point where you
>> inserted your reply).
>>
>> Another post suggested a workaround by defining a 'pocket' class, for
>> which I am grateful.
>>
>> John
>
> Sorry.  I shot off my answer before reading the whole post.  That's
> never a good idea.
>
>
> After reading to the end, I rather like your suggestion.  It works well
> in your example, , nicely avoids the C/C++ trap, and has some
> consistency with other parts of Python.
>
> Gary Herron
>
>

I liked the look of this as well.  It ought to go to python ideas, or 
has it been suggested there in the past?

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Ifs and assignments Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-03 01:20 +0000

csiph-web