Indentation style...

Emile van Sebille emile at fenx.com
Mon May 28 12:13:40 EDT 2001


>From the Python Language Reference:
"""2.1.7 Indentation
Leading whitespace (spaces and tabs) at the beginning of a logical line is
used to compute the indentation level of the line, which in turn is used to
determine the grouping of statements.

First, tabs are replaced (from left to right) by one to eight spaces such
that the total number of characters up to and including the replacement is a
multiple of eight (this is intended to be the same rule as used by Unix).
The total number of spaces preceding the first non-blank character then
determines the line's indentation. Indentation cannot be split over multiple
physical lines using backslashes; the whitespace up to the first backslash
determines the indentation. """

Which says that tabs will be replaced by spaces, padded out to the next
multiple of 8.  This allows for blocks such as:

def test()
    i = 1
    if i == 1:
     print "space tab"
      print"space space tab"
       print "space space space tab"

where the printed descriptions indicate the leading whitespace. (But I don't
expect ths cut-n-paste to show it.)

--

Emile van Sebille
emile at fenx.com

---------
"Bernhard Herzog" <bh at intevation.de> wrote in message
news:6qlmnhsjdt.fsf at abnoba.intevation.de...
> Thomas Wouters <thomas at xs4all.net> writes:
>
>
> > The interpreter will treat a tab as 8 spaces. Always.
>
> Well, not exactly. The following code is syntactically correct (at least
> in the sense that Python 2.1 doesn't produce a syntax error):
>
> # tab-width:4
>
> def f():
>     a = 1      # four spaces indent
> b = 2  # one tab indent
>
> The Python tokenizer recognizes various forms of the tab-width comment.
> I'm not sure it's documented anywhere except in the sources.
>
>
>   Bernhard
>
> --
> Intevation GmbH                                 http://intevation.de/
> Sketch                                 http://sketch.sourceforge.net/
> MapIt!                                               http://mapit.de/





More information about the Python-list mailing list