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


Groups > comp.lang.python > #63007

Re: Ifs and assignments

From Roy Smith <roy@panix.com>
Newsgroups comp.lang.python
Subject Re: Ifs and assignments
Date 2014-01-02 18:36 -0500
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <roy-8601CA.18361502012014@news.panix.com> (permalink)
References <52C59FF6.5000607@allsup.co> <52C5BD90.9020609@islandtraining.com> <mailman.4811.1388704420.18130.python-list@python.org>

Show all headers | View raw


In article <mailman.4811.1388704420.18130.python-list@python.org>,
 John Allsup <pydev@allsup.co> wrote:

> if testFunc() as x:
> 	  do something with x

+1

The most common place I wish for an atomic "test and assign" is with 
regexes, as in your examples.  This would be so much nicer than what we 
have to do now:

    if re.match(string) as m:
        print m.group(0)

The analogy to

    except SomeError as ex:

is very clear.  They are both "Perform some action, capture the result, 
do some test on it, and then make that captured value available bound to 
a name".

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


Thread

Re: Ifs and assignments John Allsup <pydev@allsup.co> - 2014-01-02 21:44 +0000
  Re: Ifs and assignments Roy Smith <roy@panix.com> - 2014-01-02 18:36 -0500
    Re: Ifs and assignments Chris Angelico <rosuav@gmail.com> - 2014-01-03 11:07 +1100
    Re: Ifs and assignments Chris Angelico <rosuav@gmail.com> - 2014-01-03 11:06 +1100
    Re: Ifs and assignments Ethan Furman <ethan@stoneleaf.us> - 2014-01-02 20:16 -0800
    Re: Ifs and assignments Chris Angelico <rosuav@gmail.com> - 2014-01-03 16:35 +1100

csiph-web