Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63011
| References | <52C59FF6.5000607@allsup.co> <52C5BD90.9020609@islandtraining.com> <mailman.4811.1388704420.18130.python-list@python.org> <roy-8601CA.18361502012014@news.panix.com> <CAPTjJmoA130Q4+2PHLWiPp1FNaB+c6HgUTWpst4Z_qL3qqoR2w@mail.gmail.com> |
|---|---|
| Date | 2014-01-03 11:07 +1100 |
| Subject | Re: Ifs and assignments |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4813.1388707688.18130.python-list@python.org> (permalink) |
On Fri, Jan 3, 2014 at 11:06 AM, Chris Angelico <rosuav@gmail.com> wrote: > Pass any object through truth() and it'll either stay the same (if > it's true) or become this object (if it's false). You can then carry > on with other method calls, and they'll all happily return false. > > result = ( > truth(re1.match(string)).group(0) or > truth(re2.match(string)).group(0) or > truth(re3.match(string)).group(0) or > default_value > ) Oh, just thought of a possible snag. Since an empty string comes up as false, this exact notation would fail if the re can match nothing. But you probably know if it's possible for that to happen, so don't use this simple short-hand. :) ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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