Why Python style guide (PEP-8) says 4 space indents instead of 8 space??? 8 space indents ever ok??

Francis Avila francisgavila at yahoo.com
Wed Oct 22 19:14:57 EDT 2003


"David C. Fox" <davidcfox at post.harvard.edu> wrote in message
news:FYDlb.2596$e01.5531 at attbi_s02...
> In Python, newlines are significant, except within lists, tuples, etc.
> and a few other cases, so you generally have to escape them with \
> within statements.  If you use 8-space indents in Python, you very
> quickly end up having to escape a lot of new lines, which is annoying.


As a side note, Python considers a tab to be == 8 spaces.  So you can mix
spaces and tabs in a single file as long as you use an 8-space convention.
Now, if your editor displays \t as something other than 8 spaces (I think 8
is default in almost every editor, though), the indentation can LOOK wrong,
even though Python has no trouble with it!

Given that 4 spaces is overwhelmingly dominant in Python code, shouldn't
that behavior be changed, so that '\t'==' '*4?

Or perhaps python should have a heuristic, where the first first-level
indent in the file which is indented entirely by spaces establishes the
number of spaces that a tab character should be equivalent to.

(Or maybe it shouldn't, since mixing spaces and tabs is bound to cause
trouble eventually, and better to find out sooner than later...)
--
Francis Avila





More information about the Python-list mailing list