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


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

Re: Ifs and assignments

Started byMark Lawrence <breamoreboy@yahoo.co.uk>
First post2014-01-03 01:20 +0000
Last post2014-01-03 01:20 +0000
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: Ifs and assignments Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-03 01:20 +0000

#63017 — Re: Ifs and assignments

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-01-03 01:20 +0000
SubjectRe: Ifs and assignments
Message-ID<mailman.4819.1388712057.18130.python-list@python.org>
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

[toc] | [standalone]


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


csiph-web