Why not enforce four space indentations in version 3.x?

David Bolen db3l.net at gmail.com
Fri Jul 17 19:09:35 EDT 2009


Nobody <nobody at nowhere.com> writes:

> On Thu, 16 Jul 2009 09:18:47 -0500, Tim Chase wrote:
>
>> Yes, the dictatorial "a tab always equals 8 spaces"
>
> Saying "always" is incorrect; it is more accurate to say that tab stops
> are every 8 columns unless proven otherwise, with the burden of proof
> falling on whoever wants to use something different.

I suspect Tim was referring to the Python tokenizer.  Internally,
barring the existence of one of a few Emacs/vi tab setting commands in
the file, Python always assigns the logical indentation level for a
tab to align with the next multiple-of-8 column.  This is unrelated to
how someone might choose to display such a file.

So mixing tabs and spaces and using a visual display setting of
something other than 8 for the tab size (other than one consistent
with an instruction embedded in the file) can yield a discrepancy
between what is shown on the screen and how the same code is perceived
by the Python compiler.  This in turn may cause errors or code to
execute at different indent levels than expected.  Thus, in general,
such a mixture is a bad idea, and as per this thread, no longer
permitted in a single block in Python 3.x.

-- David



More information about the Python-list mailing list