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


Groups > comp.lang.python > #82014 > unrolled thread

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

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2014-12-05 11:30 -0700
Last post2014-12-05 11:30 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

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

FromIan Kelly <ian.g.kelly@gmail.com>
Date2014-12-05 11:30 -0700
SubjectRe: Tabs for indentation & Spaces for alignment in Python 3?
Message-ID<mailman.16635.1417804287.18130.python-list@python.org>

[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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web