Python indentation (3 spaces)

Marko Rauhamaa marko at pacujo.net
Mon Oct 15 00:45:16 EDT 2018


Chris Angelico <rosuav at gmail.com>:
> I'm saying I have never seen is this:
>
> On Mon, Oct 15, 2018 at 8:56 AM Marko Rauhamaa <marko at pacujo.net> wrote:
>> However, it is trumped by an older
>> convention whereby the indentation levels go as follows:
>>
>>    0:
>>    1: SPC SPC
>>    2: SPC SPC SPC SPC
>>    3: SPC SPC SPC SPC SPC SPC
>>    4: TAB
>>    5: TAB SPC SPC
>>    6: TAB SPC SPC SPC SPC
>>    7: TAB SPC SPC SPC SPC SPC SPC
>>    8: TAB TAB
>
> Specifically that two-space indents and tab-collapsing are a
> *convention*. I have never seen this used anywhere, much less seen it
> commonly enough to call it a convention.

The two-space indentation is the out-of-the-box default for emacs.
However, the tab collapsing principle is a universal default. If you go
against it, you will have to educate more tools than your editor. For
example, try running this Python snippet (in REPL or as a program):

    for i in range(32):
        print("x{}\ty".format(" " * i))


Marko



More information about the Python-list mailing list