when used within an if/else fails

Evan Driscoll driscoll at
Wed Nov 28 21:08:15 CET 2012

On 11/28/2012 01:57 PM, Ian Kelly wrote:
> Yes, it's best to use either tabs-only or spaces-only.  Quoting from PEP
> 8 on the subject:
>     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. 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!
>     For new projects, spaces-only are strongly recommended over tabs.
>     Most editors have features that make this easy to do.
> I thought the prohibition against mixing tabs and spaces was made more
> strict in Python 3, but I can't find any reference to that now. 
> Probably I was mistaken.

I'm only entering this thread now so I'm not really in context, but
you're correct; in Python 3, -tt is set by default, which makes illegal
mixing an error.

However, not all mixing is illegal: what it means by "code that
illegally mixes tabs and spaces" is "code whose interpretation differs
depending upon the interpretation of the tab width". While I'm not going
to go test it, I think that if you, say, indent from the first to the
second level with tabs (consistently), indent from the second to third
level with spaces (consistently), and indent from the third to fourth
level with tabs (consistently), it should not complain. Or perhaps I
should say "it should complain that you're a bad person and should feel
bad, but it won't." :-) (In fact, you could indent one block at the
second level with tabs and another with spaces.)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 554 bytes
Desc: OpenPGP digital signature
URL: <>

More information about the Python-list mailing list