Collective memory

Ben Hutchings ben-public-nospam at decadentplace.org.uk
Sun Jul 6 10:24:43 EDT 2003


In article <3f071e0c.4620472 at news.ocis.net>, Gene Wirchenko wrote:
> Irmen de Jong <irmen at -NOSPAM-REMOVETHIS-xs4all.nl> wrote:
> 
>>Charles Shannon Hendrix wrote:
<snip> 
>> >     if <something>
>> >         <work>
>> >         <more work>
>> >         <add numbers>
>> >
>> > Is <add numbers> part of the if statement, or did someone with different
>> > tab settings from the author make a mistake and align it accidentally?
>>
>>To catch such mistakes, Python has the -tt command line option:
>>-t     : issue warnings about inconsistent tab usage (-tt: issue errors)
> 
>      What is inconsistent about the tab usage above?  That is, why
> would it be flagged?
<snip>

If the above used only tabs for indentation, there could be no
question about how the statements were meant to be grouped.
Similarly, if it used only spaces for indentation, there could be no
question.  The problematic case that CSH is worried about is where the
code uses a mixture of spaces and tabs (this is what is meant by
"inconsistent"), e.g.:

<SP><SP><SP><SP>if <something>:
<SP><SP><SP><SP><SP><SP><SP><SP><work>
<SP><SP><SP><SP><SP><SP><SP><SP><more work>
<HT><add numbers>

In a text editor misconfigured to use 4-space tabs this appears as:

    if <something>:
        <work>
        <more work>
    <add numbers>

but since Python uses 8-space tabs it really means:

    if <something>:
        <work>
        <more work>
        <add numbers>

So there is a risk here, and it's probably worth adopting a rule of
not using tabs in Python code.  If you think a colleague broke the
rule, the -t flag will alert you to any potential problems.

-- 
Ben Hutchings  |  personal web site: http://womble.decadentplace.org.uk/
Man invented language to satisfy his deep need to complain. - Lily Tomlin




More information about the Python-list mailing list