No "side effect" assignment!
Asun Friere
afriere at yahoo.co.uk
Mon Sep 15 03:10:34 EDT 2003
Dave Kuhlman <dkuhlman at rexx.com> wrote in message news:<bk2okk$nrhg9$1 at ID-139865.news.uni-berlin.de>...
> Tobiah wrote:
>
> [snip]
> >
> >
> > I can't seem to do this in python without gagging:
> >
> > foo = getmore()
> > while foo:
> > process(foo)
> > foo = getmore()
>
> Then test your gag reflex on the following:
>
> while 1:
> foo = getmore()
> if not foo:
> break
> process(foo)
>
> Slips down pretty smoothly with me.
>
> [snip]
>
> Dave
I am alone in feeling some slight unease at the sight of "while 1: ...
break"? I know this is considered somewhat pythonic, but apart from
the fact that there is only a single assignment statement is there
really any advantage to be gained by doing it this way? It seems to
be trading one aesthetic disadvantage for another, and imho, a
marginally less legible one.
In terms of pandering to newbies, I think the requirement that loop
conditions be expressions is much more squarely aimed at experienced
programmers, who would otherwise be tempted to write unintelligible
code by placing too much of the programs logic withing the loop
condition.
More information about the Python-list
mailing list