[Python-Dev] Informal educator feedback on PEP 572 (was Re: 2018 Python Language Summit coverage, last part)
Greg Ewing
greg.ewing at canterbury.ac.nz
Wed Jun 27 19:44:19 EDT 2018
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
More information about the Python-Dev
mailing list