[issue11433] syntax error at "while" statement in IDLE/python shell

Victor report at bugs.python.org
Mon Mar 7 17:54:44 CET 2011


New submission from Victor <victorywin5 at yahoo.com>:

Hi and please help me understand if it is a bug, or..,as someone said, there's a 'bug' in my understanding:
(Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win32) (windows vista, the regular windows python installer)
It's about the following code:

while True:
    s = input('Enter something : ')
    if s == 'quit':
        break
    print('Length of the string is', len(s))
print('Done')

when I put it in the IDLE's editor, and run it from there ("Run module F5"), it runs fine; but when I try to type it in the python shell (IDLE), or in the python command line, it gives errors, though I tried to edit it differently:

>>> while True:
        s = input('Enter something : ')
        if s == 'quit':
            break
        print('Length of the string is', len(s))
print('Done')
SyntaxError: invalid syntax
>>> while True:
        s = input('Enter something : ')
        if s == 'quit':
            break
        print('Length of the string is', len(s))
    print('Done')
SyntaxError: unindent does not match any outer indentation level
>>>

The only way I noticed it would accept is to set the last "print" statement directly under/in the block of "while": which is not the intention. (According to the docs, while statement should work without the "else" option). Is this a bug?
Thanks, Victor
p.s. the example is taken from http://swaroopch.com/notes/Python_en:Control_Flow

----------
components: IDLE
messages: 130261
nosy: victorywin
priority: normal
severity: normal
status: open
title: syntax error at "while" statement in IDLE/python shell
type: behavior
versions: Python 3.2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11433>
_______________________________________


More information about the Python-bugs-list mailing list