osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Python-Dev] Informal educator feedback on PEP 572 (was Re: 2018 Python Language Summit coverage, last part)


Ivan Pozdeev via Python-Dev wrote:
> for me, the primary use case for an assignment expression 
> is to be able to "catch" a value into a variable in places where I can't 
> put an assignment statement in, like the infamous `if re.match() is not 
> None'.

This seems to be one of only about two uses for assignment
expressions that gets regularly brought up. The other is
the loop-and-a-half, which is already adequately addressed
by iterators.

So maybe instead of introducing an out-of-control sledgehammer
in the form of ":=", we could think about addressing this
particular case.

Like maybe adding an "as" clause to if-statements:

    if pattern.match(s) as m:
       do_something_with(m)

-- 
Greg