achates wrote:

> Duncan Booth wrote:
> 
>>However the important thing is that a tab does
>>not map to a single indentation level in Python: it can map to any
>>number of indents, and unless I know the convention you are using to
>>display the tabs I cannot know how many indents are equivalent to a
>>tabstop. 
> 
> Sorry but this is just wrong. Python works out the indentation level
> for a source file dynamically: see
> http://docs.python.org/ref/indentation.html. The particular algorithm
> it uses is designed to accommodate people who mix tabs and spaces
> (which is unfortunate, and should probably be changed). Nevertheless,
> using tabs only, one tab does indeed map to exactly one indentation
> level. One tabstop == one indent, on your editor and on mine.

Please be careful how much you trim. I also wrote:

> Using spaces everywhere allows this, using tabs everywhere 
> allows this, mixing spaces and tabs is a bad thing.

Yes, if you use tabs only tabs map to exactly one indentation level, but
as soon as there is a mix it breaks horrible. The problem arises because
in most situations there is no visual distinction between tabs and
spaces so it isn't obvious when there is an accidental mix until things
break. 

Fortunately Python is reasonably robust, and in most cases you will get
a syntax error instead of a silent change to the meaning of the code. 

> You do not need to know my display convention to run my code.

The Python interpreter does not know your display convention either: it
assumes that tabs expand to 8 character boundaries. So long as you have
pure tabs this doesn't matter, but if there is any mixing it means that
any editor set to expand tabs to a different width will no longer
display the indentation as the interpreter sees it.

The problem is that although you are a tab purist (as I am a space purist), 
too many people out there are neither. If you set an editor to only insert 
spaces then it is unlikely to accidentally insert tabs, but if the editor 
is set up to do indentation with tabs then a naive user is still likely to 
use the space bar occasionally and then wonders why Python is complaining 
about an error when they can see (with their 4 space indents) that 
everything is indented correctly.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to