while (a=b()) ...

Andrew Clover esuzm at primrose.csv.warwick.ac.uk
Sun May 9 15:14:10 EDT 1999


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.

 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.

 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)

 But this is all getting a bit functional programming. :-) Python's not my
ideal language, but it sure as hell is more intuitive than anything else I've
met. Programs even work first time, which is a tribute to it.

-- 
This posting was brought to you by And Clover.
(Sorry.)




More information about the Python-list mailing list