Python Idiom Question

Chris Barker chrishbarker at home.net
Tue Jul 10 18:33:34 CEST 2001


Steve Holden wrote:

> > The approved idiom is
> while 1:
>     x = raw_input()
>     if not x:
>         break
>     DoSomethingInteresting()

This is the approved idiom, but I never use it. I always use:

x = raw_input()
while x:
    x = raw_input()
    DoSomethingInteresting()
    x = raw_input()

I really don't like any "while 1" constructs, you have to then go
looking for the "break" to find out what is controlling the loop. I
don't like having to put "x = raw_input" in two places either, but it's
more clear to me this way. That's why I wish Python had a "do until:" or
something like it, and I am looking forward to  iterators and
generators. (and am very ahppy about file.xreadlines)

-Chris


-- 
Christopher Barker,
Ph.D.                                                           
ChrisHBarker at home.net                 ---           ---           ---
http://members.home.net/barkerlohmann ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------



More information about the Python-list mailing list