Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #57748

Re: indentation blocking in Python

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'from:addr:yahoo.co.uk': 0.04; 'output': 0.05; 'subject:Python': 0.06; 'explanation': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'tismer': 0.09; 'python': 0.11; 'block.': 0.16; 'colon.': 0.16; 'indent': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'think.': 0.16; 'write.': 0.16; 'language': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'all,': 0.19; 'bit': 0.19; 'file,': 0.19; 'thanks.': 0.20; 'programming': 0.22; 'rules': 0.22; 'this?': 0.23; 'header:User-Agent:1': 0.23; 'instance,': 0.24; 'looks': 0.24; 'question': 0.24; 'second': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'dos': 0.30; 'errors': 0.30; 'code': 0.31; 'block,': 0.31; 'supposed': 0.32; 'running': 0.33; 'maybe': 0.34; 'but': 0.35; 'christian': 0.38; 'window': 0.38; 'to:addr:python- list': 0.38; 'little': 0.38; 'anything': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'new': 0.61; 'world.': 0.61; 'offer': 0.62; 'email addr:gmail.com': 0.63; 'obvious.': 0.84; 'received:2': 0.84; 'semi': 0.84; 'works!': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: indentation blocking in Python
Date Sun, 27 Oct 2013 15:44:59 +0000
References <96fc985d-725e-4fe7-8d30-0bcaad91f975@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host host-2-98-201-160.as13285.net
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.0.1
In-Reply-To <96fc985d-725e-4fe7-8d30-0bcaad91f975@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1651.1382888712.18130.python-list@python.org> (permalink)
Lines 39
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1382888712 news.xs4all.nl 15938 [2001:888:2000:d::a6]:33547
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:57748

Show key headers only | View raw


On 27/10/2013 15:31, ajetrumpet@gmail.com wrote:
> hello all,
>
> This has got me a tad bit confused I think.  I am running 3.3.0 and I know that Python looks to group code together that is supposed to be in the same block.  But the question is, where are the rules for this?  For instance, if I type the following in a PY file, it errors out and I don't see the DOS window with the output in Vista:
>
> a=1;
>     if a==1: print(1)
>     else: print(0)
> wait = input("press key")
>
> However, if I don't indent anything at all, it works!
>
> a=1;
> if a==1: print(1)
> else: print(0)
> wait = input("press key")
>
> Can someone offer just a little explanation for this?  'IF' and 'ELSE' are obviously in the same code block.  Are they not?  Maybe it's not so obvious.  Thanks.
>

You don't have a new block, the if else is in the same block as a=1, 
which by the way doesn't need that semi colon.  Restructure the if else 
and you must then write.

a=1
if a==1:
     print(1)
else:
     print(0)
wait = input("press key")

HTH.

-- 
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

indentation blocking in Python ajetrumpet@gmail.com - 2013-10-27 08:31 -0700
  Re: indentation blocking in Python "Colin J. Williams" <cjw@ncf.ca> - 2013-10-27 11:37 -0400
  Re: indentation blocking in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-10-27 15:44 +0000
  Re: indentation blocking in Python Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2013-10-27 16:40 +0100

csiph-web