Testing conditions.

Terry Reedy tjreedy at udel.edu
Thu Feb 10 02:14:56 EST 2005


"Ray Gibbon" <ray at rgibbon.freeserve.co.uk> wrote in message 
news:cues7q$mg7$1 at news7.svr.pol.co.uk...
> e.g. 1
> |    while new_data = get_more_data(source):
> |        process_data(new_data)
>
> is obviously the sort of thing I'm missing, but it is not a general 
> solution
> because :-
>
> e.g. 2
> |    while new_data, environment = get_more_data(source):
> |        process_data(new_data, environment)
>
> is something I'm equally likely to want to do, but I can't express it's
> meaning.

The other problem with while loops, even if assignment were allowed, is 
that the loop stops on any null (False) value.  So you soon would need to 
have the assignment buried within a comparison expression, as in C.

> Before I resign myself to the inevitable, 'that's the way it is - get 
> used
> to it', I'd just like to scratch it once.  But, before I try walking on 
> very
> thin ice, I want to ask whether there are expectations of some future
> changes which address these issues?

As Jeremy already implicitly pointed out, for loops already address these 
issues by combining assignment and a stop test, with the stop test being 
for a StopIteration exception rather than a null value.  Separating data 
generation and validation from data processing is much cleaner.

Terry J. Reedy






More information about the Python-list mailing list