statements in control structures (Re: Conditional Expressions don't solve the problem)

Terry Reedy tjreedy at home.com
Thu Oct 18 20:13:59 EDT 2001


"Huaiyu Zhu" <huaiyu at gauss.almadan.ibm.com> wrote in message
news:slrn9sua6b.k8.huaiyu at gauss.almadan.ibm.com...
> Here are 6 examples [from standard library]

Most should be rewritten with iterators.  No other new syntax is
needed.

Then there is this:

> Lib/ftplib.py:
> --------------------------------------------(3)
>     def getmultiline(self):
>         line = self.getline()
>         if line[3:4] == '-':
>             code = line[:3]
>             while 1:
>                 nextline = self.getline()
>                 line = line + ('\n' + nextline)
>                 if nextline[:3] == code and \
>                         nextline[3:4] != '-':
>                     break
>         return line
>
> changed to
>
>     def getmultiline(self):
>         code = None
>         lines = []
>         while line = self.getline(); lines.append(line); line[3:4]
== '-':
>             if code != line[:3]: break
>             else: code = line[:3]
>         return '\n'.join(lines)

Thanks for finding some concrete, realistics examples of what the
proposed change would lead to.  To me, that 'while' line is convincing
evidence againt this syntax.  What bothers me is this.  ';' is a
statement separator (whose use is generally discouraged).  What the
proposed change means is that a 'while' at the beginning of the
sequence means that the last statement is instead to be a condition.
This requires a sort of mental suspension that I believe many besides
me would find obnoxious.

Terry J. Reedy






More information about the Python-list mailing list