Sumbline Text 2, Eclipse all acting up, Indentatio

2019-09-08 15:29发布

问题:

I'm having a problem with python interpreters. It happened 2nd time in recent months and is very frustrating. This is my code:

When I run this, the interpreter raises an error:

else: ^ IndentationError: unindent does not match any outer indentation level

same is occuring on Eclipse.

I typied code by hand, no copy/pase, tried to fix it many times and the error is not subsiding. Although the code is 100% corrent. When I remove else: pass part it even sometimes raises open_odds is not defined error.

Have you guys had similar problems? Even python IDLE is now acting up on the same code line, the same error. I can no longer work ;/.

回答1:

You are mixing tabs and spaces. Don't do that.

Run your script with python -tt then fix the errors that finds.

Next, configure your editor to only use spaces:

  • View -> Indentation -> Indent Using Spaces
  • View -> Indentation -> Tab Width: 4
  • View -> Indentation -> Convert Indentation to Spaces

and perhaps set that as the default for Python. See Indentation settings in the Sublime Text 2 documentation.