Re: Minor bug, perhaps? + (PC-Python/CS1)

Guido van Rossum (Guido.van.Rossum@cwi.nl)
Thu, 13 Aug 1992 11:36:23 +0200

Stoffel,

Glad to hear your opinion about Python's "teachability"!

Regarding your problem I was afraid this would happen some day!

>Here we have an assignment statement following directly on a `one-line' if:
> ...
> if i==n: break
> j = i
> ...

Looking carefully at your example, there are 8 spaces before the "if",
but two tabs before the "j = i" line. (I'm glad that e-mail doesn't
mess with tabs, most of the time!) In my source, both lines begin
with two tabs. So I suspect that you've been editing the file in an
editor that believes in 4 spaces per tab and somehow the editor
decided to replaces the tabs on the first line by the "equivalent"
number of spaces (e.g. because you touched the line with the cursor).

There are several ways to fix this:

(0) Find a clean backup of the library files with all the tabs in
them. (This is probably necessary anyway, to avoid surprises.)

(1) Change your editor's idea of tab size (this may or may not be
possible).

(2) Replace all tabs by a consistent number of spaces, and never use
tabs when editing. Now it doesn't matter how many spaces you use as
long as you are consistent (Python doesn't require indented lines to
be indented by a specific number of spaces, as long as you are
consistent.) The function expandtabs() in string.py shows how to do
this in Python.

(3) Use an undocumented feature of the Python interpreter which
changes Python's idea of how many spaces a tab is worth: in the
beginning of each file, insert a comment of the form

# vi:set tabsize=N:

where N is the desired tab size (e.g. 4).

Note that if you *only* use spaces for indentation you never run into
trouble; if you *only* use tabs, it likewise can't go wrong; but if
you start mixing the two, it's important that your editor and Python
have the same idea of tab size. There should probably be a command
line option to set the interpreter's default tab size (in fact on the
Mac the default is 4 because all editors there use that default...).

--Guido van Rossum, CWI, Amsterdam <guido@cwi.nl>
"You are all individuals!" "We are all individuals!"