Python indentation (3 spaces)

Chris Angelico rosuav at gmail.com
Fri Oct 5 17:41:27 EDT 2018


On Sat, Oct 6, 2018 at 7:25 AM Serhiy Storchaka <storchaka at gmail.com> wrote:
>
> 05.10.18 23:53, Chris Angelico пише:
> > I don't understand how three spaces would prevent errors in a way that
> > four wouldn't.
> In many editors and on terminal
>
> for a in x:
>      if a:
>          b()
> <-tab-->c()
>
> looks indistinguishable from
>
> for a in x:
>      if a:
>          b()
>          c()
>
> but the former is a syntax error in Python 3.

Considering that 8-space tabs are at least as common as 4-space, and
that tabs measured in millimeters are also entirely viable, I don't
think there's any way to define this perfectly consistently. It
depends entirely on the particular setup that you have, and therefore
is perfect for a per-project style guide.

But hey. It's an instant syntax error. It's not exactly hard to fix.
Some editors (including the one I use - SciTE) will highlight
mismatched indentation right there as you type.

ChrisA



More information about the Python-list mailing list