Python Idiom Question

Alex Martelli aleaxit at yahoo.com
Tue Jul 10 17:38:45 EDT 2001


"Chris Barker" <chrishbarker at home.net> wrote in message
news:3B4B2E5E.AB3C94BD at home.net...
> 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()

So you always throw away 50% of the raw input you receive?
Peculiar indeed!

> 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

Above, you're using it in three places.  I think your preferred
construct is error-prone, as evidenced here:-).


Alex






More information about the Python-list mailing list