Tabs for indentation & Spaces for alignment in Python 3?

Michael Torrie torriem at gmail.com
Sat Dec 6 11:41:57 EST 2014


On 12/06/2014 01:40 AM, Marko Rauhamaa wrote:
> Michael Torrie <torriem at gmail.com>:
> 
>> In fact a decent editor that is auto-indenting code would, at least in
>> C or C++ mode, do that automatically.
> 
> A decent editor frees you from this dilemma entirely:
> 
>     (custom-set-variables
>      '(indent-tabs-mode nil))

What dilemma?  Do you mean you can avoid the drama of tabs by going all
spaces?  Of course in Python this is the recommended course.

But that's typically not what I, or most people, use in C or C++.  And
one of the OP's points is that by using tabs for indent, and spaces for
alignment, you can have the best of both worlds.  Programmers can set
their tab size to anything they want, and it still looks good (except of
Linux kernel source code, which only will ever look right at tabs
equivalent to 8 spaces).  He wanted to know if he could still do that in
Python3, and the answer is "yes" although we recommend highly just
sticking to pep8 4 space characters per indent and no tabs whatsoever.

Of course any validly-formatted Python code (or C code) can be made to
look right and work right by running autopep8[1] on it.  Just like
"indent" can make your C code fit whatever style guide you need.

[1] https://pypi.python.org/pypi/autopep8/



More information about the Python-list mailing list