Tabs and spaces (style)

John Roth johnroth at ameritech.net
Sun Jun 3 13:33:07 EDT 2001


"Lloyd Hugh Allen" <vze2f978 at mail.verizon.net> wrote in message
news:3B1A41CA.CCE5197A at mail.verizon.net...
> Fredrik Lundh wrote:
> >
> > Alex Martelli wrote:
> > > > What is the consensus about mixing tabs and spaces in a Python
script?
> > >
> > > I don't think there is one.  Guido's style guide recommends using
both,
> > > with a tabsize of 8, so I expect most Pythonistas follow that style.
Yet,
> > > for what it counts, I personally prefer setting my editors to always
save
> > > with spaces only
> >
> > note that the standard distribution uses spaces throughout.  guess
> > GvR hasn't gotten around to update the style guide...
> >
> > Cheers /F
>
> I thought that that was so that I could have a use for my old (paper)
> Fortran program templates.

Guido's style guide, from http://www.python.org/doc/essays/styleguide.html
says, and I quote via cut and paste:

Indentation

Use the default of Emacs Python-mode: 4 spaces for one indentation level.
For really old code that you don't want to mess up, you can continue to use
8-space tabs. Emacs Python-mode auto-detects the prevailing indentation
level used in a file and sets its indentation parameters accordingly.

Tabs or Spaces?

Never mix tabs and spaces. The most popular way of indenting Python is with
spaces only. The second-most popular way is with tabs only. Code indented
with a mixture of tabs and spaces should be converted to using spaces
exclusively. (In Emacs, select the whole buffer and hit ESC-x untabify.)
When invoking the python command line interpreter with the -t option, it
issues warnings about code that illegally mixes tabs and spaces. When
using -tt these warnings become errors. These options are highly
recommended!

<end quote>

The common wisdom is that since you cannot trust tools to implement tabs
consistently, they
should be avoided. Otherwise, you wind up with real inconsistent indentation
when you try to
print, or otherwise process a program.

John Roth





More information about the Python-list mailing list