[Tutor] Break stament issue
Steven D'Aprano
steve at pearwood.info
Wed Jun 15 00:40:26 CEST 2011
Susana Iraiis Delgado Rodriguez wrote:
> Hello members!
>
> I'm doing a script that needs to loop to get some information, in order to
> do that I'm using modules from OGR and Mapnik. These to get data from
> shapefiles, but some of the files have 0 elements, I wrote a line to
> validate it, but it hasn't worked, so I added a break to keep working. When
> I run the scipt I got the next error:
> Traceback (most recent call last):
> File "<pyshell#0>", line 1, in <module>
> import mapnik_punto_sin_duda
> File "C:\Python26\mapnik_punto_sin_duda.py", line 23
> break
> ^
> IndentationError: unexpected indent
This error has nothing to do with break. Look at the error message, and
the position of the ^ mark: the error occurs *before* the break
statement, in the indentation.
I can duplicate the error in Python 2.6 with this:
>>> for t in (1, 2, 3):
... print t # four spaces
... break # one tab
File "<stdin>", line 3
break # one tab
^
IndentationError: unexpected indent
Newer versions of Python give more helpful error messages: Python 3
reports "TabError: inconsistent use of tabs and spaces in indentation".
You can fix this by using the tabnanny script supplied with Python. From
the shell (not Python's interactive interpreter!) or the DOS prompt, run:
python -m tabnanny -v <path to your file>
replacing <path to your file> with the actual filename, and see what it
says.
--
Steven
More information about the Tutor
mailing list