how to finish a while loop...

Preston Landers planders at gmail.com
Tue Feb 19 20:48:48 EST 2008


On Feb 19, 7:35 pm, icarus <rsa... at gmail.com> wrote:

> > But when I paste it into eclipse and run it
> > eclipse's console, it doesn't work because answer seems to have a
> > stray '\r' carriage return (CR) and therefore the comparison to 'no'
> > fails.
>
>           I get no 'compile' errors there.
>           I get regular execution but it just doesn't change the
> condition to False at the very end.
>           Therefore it loops forever.  I used other values like zeros
> and ones to make sure I could print the values when the interpreter
> got down to that line.  Everything checked.  Just didn't change the
> condition on the main loop.

I'm pretty sure this is an eclipse console issue.  Since you have it,
try stepping through the program in the debugger and inspect the
answer variable after raw_input returns.  On my setup, at that point
answer is 'no\r', but raw_input() is supposed to strip line endings.
I'm guessing the console supplied 'no\r\n' and only the \n was
stripped.  Could be that python does not recognize that eclipse's
console uses CRLF line endings.

As a workaround you can do raw_input().strip().

You might check the eclipse issue tracker to see if this a known
issue.

Preston



More information about the Python-list mailing list