Tabs -vs- Spaces: Tabs should have won.

Ian Kelly ian.g.kelly at gmail.com
Sun Jul 17 09:39:48 CEST 2011


On Sun, Jul 17, 2011 at 1:29 AM, Andrew Berg <bahamutzero8825 at gmail.com> wrote:
> You're right. TabError is only raised if the initial indentation is
> inconsistent.
> Not legal:
> def spam():
> <tab>print('Wonderful spam!\n')
> <4 spaces>print('Bloody Vikings!')
>
> Legal:
> def eggs():
> <tab>print(
> <tab><tab>'Blech!\n',<some spaces to align>'Whaddya mean, "blech"?\n',
> <tab><tab>'I don\'t like spam!\n',<spaces to align>'...'
> <tab><tab>)

Even this is legal:

def eggs()
<tab>if spam:
<tab><spaces>print("Spam and eggs")
<tab>else:
<tab><tab>print("Just eggs")

It's only when you're inconsistent about the added indent of a single
block that Python will complain.



More information about the Python-list mailing list