Welcome! Log In Create A New Profile

Advanced

Python error message "IndentationError: unindent does not match any outer indentation level"

Posted by BingDai 
Hi,

I am trying to use Python to compile cam.py, which is the only Gcode generator I found which takes .svg as its input.

(The source code of cam.py is [web.media.mit.edu].
The Python runs on Eclipse via a plugin called Pydev [pydev.org].)

The error message occurs:
" line += 1
^
IndentationError: unindent does not match any outer indentation level"


I know that Python is extremely strict with identation (a misuse of tab/space occurs the indentation error), so I suspect that, when I copy&paste the cam.py source code from a website into Python, I also pasted some unecessary tab/space that confuses Python.

I tried to fix the indentation problem by deleting/adding spaces to each line, but it is rather tedious, and I may accidentally create new bugs too. Therefore I am not sure how to solve this problem.

Could anyone help me with it? Thanks a lot!


-Bing

Edited 1 time(s). Last edit at 10/20/2009 01:21AM by BingDai.
Quote

BingDai Wrote:

> I know that Python is extremely strict with
> identation (a misuse of tab/space occurs the
> indentation error), so I suspect that, when I
> copy&paste the cam.py source code from a website
> into Python, I also pasted some unecessary
> tab/space that confuses Python.

You never copy and paste Pyhon Code from a website unless it has been copied from a forum which uses formatted code eg this forum has it
		for nCurvePoints in myCurvePoints:
			
			# Copy the first set of co-ordinates
			# ready for a isCyclic condtion
			if myBezPointNumber == 0:
				myFirstCoods = nCurvePoints
			
			# Apparently  BezTriple outputs 9 floats for each handle/knot in 3D space
			# so print out each float value
			print"\n##############################################"
			print"Bezier point number: %s" % myBezPointNumber
			print"Out of a total: %s" % myNumberOfPoints
			print"Current iteration at frame: %s\n" %  myCurrentPathLen
			print"H1x: %s " % nCurvePoints.vec[0][0]
			print"H1y: %s " % nCurvePoints.vec[0][1]
			print"H1z: %s " % nCurvePoints.vec[0][2]
			print"\n"
			print"Px: %s " % nCurvePoints.vec[1][0] 
			print"Py: %s " % nCurvePoints.vec[1][1] 
			print"Pz: %s " % nCurvePoints.vec[1][2]
			print"\n"
			print"H2x: %s " % nCurvePoints.vec[2][0] 
			print"H2y: %s " % nCurvePoints.vec[2][1]
			print"H2z: %s " % nCurvePoints.vec[2][2] 
			print"##############################################\n"

This is just an excerpt of a project I once did for Blender, thus it is working code

The best solution is to grab your code from its source and open it in a program like Notepad++

There you can format it, copy, paste or whatever you like but it must be a text editor (or IDE)
I have downloaded Notepad++ and tried it. It's really useful. Thanks!


-Bing
Python is based on identation.

In C++ We write something like
for(i=0;i<10;i++)
{
...
}

The code block is enclosed in { and }.

In Python, the indentation is what matters:

for i in range(10):
...

You have to make sure each indent level is the same. For example: (# denotes comments)

if i == 0:
... # indent level 1

for j in range(20):
... # indent level 2
...

... # <--- this has to be also indent level 1
... # Indent level 1 signifies end of for loop

... # <--- indent level 0 signifies end of if statement
It's essential when using Python to have a text editor that shows you the whitespace, as the whitespace is essentially part of the core. I think Notepad++ will do this, on Linux there is a plugin for gedit.
In Notepad++ it shows you each tab level, and the tab stops are like 4 white spaces, but don't use the space bar, just use the tab key
oops... just realized that my indentation didn't show up here
Sorry, only registered users may post in this forum.

Click here to login