Posted 27 November 2012 - 01:41 AM
This problem has to do with the fact that the general rule in Python is that the interpreter uses indentation to indicate blocks of code. This is only half-right: Python actually uses white-space to determine the level of indentation it is currently working at.
The TAB character counts as one white-space character as does the SPACE. When you mix TABs and the use of four SPACEs in your code, it looks OK to your eyes as the indentation distances match.... however, to Python, one TAB is one white-space character, whereas four SPACEs are four white-space characters. To Python, the code with the TAB is one level of indentation deep, whereas the code with the four SPACEs is *four* (!!!) levels of indentation deep.
And that's the problem. You have an inconsistent use of TABs and SPACEs in your code.
To fix this in IDLE, bring your code into the IDLE edit window, then select EDIT... SELECT ALL... to highlight all of the code. Then select FORMAT... UNTABIFY REGION... to convert all of your TABs into four SPACEs. That should fix things.
Also... it's probably a good idea to configure your editor to automatically replace a single key-press of the TAB key with four SPACEs. That should then stop this problem from happening again.
Hope this helps.
--Paul.