Python Indentation Problems

Terry Hancock hancock at anansispaceworks.com
Tue Feb 28 16:30:25 EST 2006


On 26 Feb 2006 22:21:26 -0800
diffuser78 at gmail.com wrote:
> I am a newbie to Python. I am mainly using Eric as the IDE
> for coding. Also, using VIM and gedit sometimes.
> 
> I had this wierd problem of indentation. My code was 100%
> right but it wont run because indentation was not right. I
> checked time and again but still no success. I rewrote the
> code over again in VI and it ran.
> 
> Can you please explain whats the trick behind the correct
> indentation.

I'm not sure about Eric, but I found that when using the
Python interpreter through a terminal window, it's often
confusingly fastidious about tabs versus spaces. You would
think that in an interactive context the interpreter would
be smart enough to fix these errors on input (e.g. by
implementing a "convert tabs to spaces" policy by default
-- I've already configured my gvim editor to do that, and
while it's not obviously the right thing to do in an
editor it seems like a no-brainer for an editing mode
whose only purpose is to run Python), but it apparently
doesn't (or didn't anyway -- either I've gotten better
about not mixing them, or it may have been fixed, or else
I'm just lucky to finally have a terminal that agrees with
the interpreter on the width of tabs).

In any case, it's good practice not to mix tabs and spaces.

I actually recommend using just tabs when playing with
the interpreter (it's faster) -- but use spaces in your real
source code files.

-- 
Terry Hancock (hancock at AnansiSpaceworks.com)
Anansi Spaceworks http://www.AnansiSpaceworks.com




More information about the Python-list mailing list