while (a=b()) ...

Phil Hunt philh at vision25.demon.co.uk
Mon May 10 12:21:06 EDT 1999


In article <3736ED9B.515704AF at starmedia.net>
           andrew at starmedia.net "Andrew Csillag" writes:
> 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.

A better solution would have been to make the assignment operator
something other than =, e.g. :=. Then it is obvious that something
like:

   while (c := curs.fetchone()):
      #...whatever...

is an assignment not a test for equality.



-- 
Phil Hunt....philh at vision25.demon.co.uk





More information about the Python-list mailing list