while (a=b()) ...

Andrew Csillag andrew at starmedia.net
Mon May 10 10:30:52 EDT 1999


scott cotton wrote:
> 
> On 9 May 1999 19:14:10 GMT, Andrew Clover wrote:
> >Nathan Clegg (nathan at islanddata.com) wrote:
> >
> >> The ideal, of course, would be:
> >
> >> while (c = curs.fetchone()): ...
> >
> >> That is my only complaint about python, that statements cannot be
> >> expressions.

In my opionion, this a feature, not a bug.  I cannot remember how many
times I accidentally typed c = NULL instead of c == NULL in C.

The problem with C is that it gives you much power, but enough rope to
hang yourself as well as many of your neighbors.

> >
> > I agree with the sentiment; I'd prefer a syntax like:
> >
> > while (c= curs.fetchone(); c!=None):
> >   ...
> >
> > Where a semicolon would throw away the value of the left expression (an
> >assignment evaluating to nothing), then return the boolean expression on the
> >right. By allowing expressions to be made up of multiple statements like
> >this, it would be easy to write nice middle-test loops.

Is this so bad?

c=curs.fetchone()
while c:
    do something with c
    c=curs.fetchone()

Is it a little redundant? Yes.  Error prone?  No.

> > Also I'd like a colon operator to return the left expression after evaluating
> >and throwing away the right, so you could write something like:
> >
> >  c= a+b: (a= 1; b= 2)
ACCK!!!


> i don't see why you like this?   what's wrong with a=1; b=2;
> c=a+b?

I've got to agree with this.

please-stop-the-insanity-and-accept-assignments-not-being-expressions-ly
yours,
Drew Csillag
-- 
"There are two major products that come out of Berkeley: 
LSD and UNIX. We don't believe this to be a coincidence." 
- Jeremy S. Anderson




More information about the Python-list mailing list