Question about indentation and bugs

Peter Hansen peter at engcorp.com
Sun Aug 26 11:15:55 EDT 2001


Bengt Richter wrote:
> 
> On Sat, 25 Aug 2001 17:12:36 -0500, Skip Montanaro <skip at pobox.com> wrote:
> [...]
> >
> >You're talking about two different things.  The standard indentation is four
> >spaces, but if you treat a TAB character as eight spaces you'll be okay
> >(though with "python -t" you might get some indentation warnings).  It's
> >when you treat a TAB character as something other than 8 spaces that mixing
> >spaces and TABs becomes a problem.
> >
> You don't literally mean that '\t' becomes ' '*8 ??

I don't think he really meant that.  Referring to TABs as
eight spaces is easier than talking about:

> are 0-79, a tab from column c goes to (c&~7)+8, so, e.g.,

..in casual conversation, not a strict definition.  (But it
sure does confuse people who don't know any better.)

> Ugh, I just tried this with python in an interactive NT
> console window (which tabs 8):
> (I've put in spaces to preserve the way it looked)
>  >>> def z():
>  ...     print 'tabbed indent'
>  ...         print '8-space indent'
>  ...
>  >>> z()
>  tabbed indent
>  8-space indent
>  >>>
> 
> That's ugly. 

I agree!  Unfortunately I suppose it's probably somewhat 
necessary, since the two prompts are programmable and therefore
you have no guarantee what size they are.  You would have to 
guess where the TAB took you on-screen, and if you allow 
control characters you'd get real messed up.  For example,

>>> import sys
>>> sys.ps2 = ''
>>> def z():
        print 'tabbed'
        print 'spaced'

>>> z()
tabbed
spaced
>>>

> IMHO indentation that looks aligned ought to act aligned,
> irrespective of tab/space mix. 

Agreed, but since the definition of Python indentation doesn't
take into account the interactive console's prompts and the
effect they have on the visual effect of TABs when sent to the
terminal (which are relative to the real left column, not the
virtual one created by the prompts), I don't think you can fix this.

-- 
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com



More information about the Python-list mailing list