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


Groups > comp.lang.python > #82014

Re: Tabs for indentation & Spaces for alignment in Python 3?

References <CAFaCOgyMf9rQCM1T52VAGB5RRyjEmATS2Cq3A8+KERsT8Pv0bg@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2014-12-05 11:30 -0700
Subject Re: Tabs for indentation & Spaces for alignment in Python 3?
Newsgroups comp.lang.python
Message-ID <mailman.16635.1417804287.18130.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Fri, Dec 5, 2014 at 10:40 AM, Aahan Krish <krish@aahan.me> wrote:
> Q2. PEP 8 also reads, "Python 3 disallows mixing the use of tabs and
spaces for indentation."
>
> So, if I am using tabs for indentation and spaces for alignment, is it
still considered "mixing the use of tabs and spaces" in Python 3? (Please
see this example.)

No, you can mix tabs and spaces as long as you do so consistently within a
block, i.e. if one line is indented with <tab><sp><sp><tab> then the next
line in the same block had better start with that same exact sequence. The
difference is that Python 2 when trying to compare indentation will treat a
tab as equal to 8 spaces (or was it 4?) which can lead to situations where
the relative indentation of two lines looks one way to the programmer but
is lexed a different way by the interpreter. Python 3 resists the
temptation to guess in this situation and simply raises an error.

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


Thread

Re: Tabs for indentation & Spaces for alignment in Python 3? Ian Kelly <ian.g.kelly@gmail.com> - 2014-12-05 11:30 -0700

csiph-web