This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Messed up indentation makes undesired piece of code being run!
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, jentyk, r.david.murray
Priority: normal Keywords:

Created on 2015-05-01 17:15 by jentyk, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg242336 - (view) Author: (jentyk) Date: 2015-05-01 17:15
In [14]: for i in xrange(10):
   ....:     if 1==1:
   ....:         print "It's true"
   ....: else:
   ....:     print "It isn't true. Seriously??"
   ....:
It's true
It's true
It's true
It's true
It's true
It's true
It's true
It's true
It's true
It's true
It isn't true. Seriously??

Is the behaviour intentional? I do not think so...
msg242338 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-05-01 17:26
Whitespace is significant in Python.  This is a fundamental part of the language.  So yes, this is intentional.  (Look up what the 'else' clause means on an if statement in the language reference.)
msg242343 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2015-05-01 17:55
I think David meant the "else" clause on a "for" statement:

https://docs.python.org/2/reference/compound_stmts.html#the-for-statement
msg242371 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-05-02 02:21
Oops.  Yes, that's what I meant :)  Thanks for the correction and link, Eric.
History
Date User Action Args
2022-04-11 14:58:16adminsetgithub: 68294
2015-05-02 02:21:37r.david.murraysetmessages: + msg242371
2015-05-01 17:55:49eric.smithsetnosy: + eric.smith
messages: + msg242343
2015-05-01 17:26:27r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg242338

resolution: not a bug
stage: resolved
2015-05-01 17:15:47jentykcreate