python3: accessing the result of 'if'

Nick Coghlan ncoghlan at iinet.net.au
Sat Jan 8 03:30:25 EST 2005


Carl Banks wrote:
> Right.  But you know that as soon as you add this to simple
> expressions, a bunch of people are going to come here whining about how
> they don't get to use where with if-expressions.
> 
> Frankly, they might have a point here.  Although we have replacing
> lambda expressions on our minds, I have in mind a different problem
> that a where-statement would solve perfectly.  But it would have to be
> used with an if-expression.

I have a different suggestion for this.

'as' is used for renaming in import statements. 'as' will be used for exception 
naming in Python 3k.

So let's use it for expression naming in 'if' statements, too.

if someregexp.match(s) as m:
   # blah using m
elif someotherregexp.match(s) as m:
   # blah using m

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net



More information about the Python-list mailing list