New syntax for blocks
pavlovevidence at gmail.com
Wed Nov 11 05:13:21 CET 2009
On Nov 10, 7:12 pm, Steven D'Aprano
<ste... at REMOVE.THIS.cybersource.com.au> wrote:
> On Tue, 10 Nov 2009 12:45:13 -0800, Bearophile wrote:
> > r:
> >> i think the following syntax would be quite beneficial to replace some
> >> redundant "if's" in python code.
> I knew it wouldn't take long for people to start responding to any
> proposal with "don't bother, there's a moratorium".
> Of course in this case, the correct response would have been "don't
> bother, it's a stupid idea, moratorium or no moratorium".
r didn't actually give a good example. Here is case where it's
actually useful. (Pretend the regexps are too complicated to be
parsed with string method.)
if re.match(r'go\s+(north|south|east|west)',cmd) as m:
elif re.match(r'take\s+(\w+)',cmd) as m:
elif re.match(r'drop\s+(\w+)',cmd) as m:
I wouldn't mind seeing this in Python for this exact use case,
although I'd rather the syntax to be more like the following so that
you can bind something other than the condition if need be.
if m with m as re.match(regexp,command):
Moot point for the next two years, and probably forever as I doubt it
would ever happen.
More information about the Python-list