Whitespace as syntax (was Re: Python Rocks!)

fcahoon at my-deja.com fcahoon at my-deja.com
Tue Feb 8 01:15:43 EST 2000


In article <1262139803-5814898 at hypernet.com>,
  gmcm at hypernet.com wrote:
> fcahoon at my-deja.com writes:
> [skip to example]
> >
> > if condition1:
> > <S><S><S><S>statement1
> > <S><S><S><S>statement2
> > <S><S><S><S>if condition2:
> > <S><S><S><S><S><S><S><S>statement3
> > <T>statement4
> >
> > To which loop does statement4 belong?
>
> Unambiguous. It belongs to "if condition2". Python interprets
> tabs as 8.

I think this should be in the Python FAQ.  Or is it, and I missed it
somehow?  If so, please excuse my oversight.

Suppose that I'm one of those set-tabs-to-logical-indentation sorts of
guys, so I set my tab width to 4, then look at this code in my editor.
Gee, it sure _looks_ like statement4 belongs to "if condition1"!  And,
if I convert tabs to spaces when I save, statement4 _will_ belong to "if
condtion1".  I've just unwittingly changed the logic of the code!

You may, of course, argue that this is unlikely, but it is still
plausible enough to make me _very_ nervous.

f

> [ ... rest snipped ... ]


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list