On Nov 10, 7:12 pm, Steven D'Aprano
<ste...@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.
>
> >http://python.org/dev/peps/pep-3003/
>
> 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:
    hero.move(m.group(1))
elif re.match(r'take\s+(\w+)',cmd) as m:
    hero.pick_up(m.group(1))
elif re.match(r'drop\s+(\w+)',cmd) as m:
    here.put_Down(m.group(1))

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.



Carl Banks
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to