[Python-Dev] final note on LANL syntax suggestions
gvwilson@nevex.com
gvwilson@nevex.com
Wed, 9 Feb 2000 10:28:35 -0500 (EST)
Just to wrap up this thread (as if): a couple of people have pointed out
that two of the suggestions that came up w.r.t. Python syntax are really
about eliminating need for assignment-as-an-operator:
do:
line = readline()
while line:
print line
gets rid of a need for:
while (line = readline()):
print line
without the confusing-for-newcomers:
while 1:
line = readline()
if not line: break
print line
and the generalized case statement:
if x is:
expr1, expr2:
x is the result of expr1 or expr2
expr3:
x is the result of expr3
else:
x is undefined or None
does:
if ((x = expr1) or (x = expr2)):
code using x
elif x = expr3:
code using x
else:
code
(Don't know what other people's experience is, but this comes up a lot in
my code when I'm doing Awk-style coding, i.e. when RE matching drives
execution.) Looking through some C++ code I wrote last year, these two
cases (loop control and capturing successful conditions) account for at
least three quarters of my uses of assignment-as-operator.
My thanks to people for pointing this out,
Greg