The following python code throws this error message, and I can't tell why, my tabs seem to be in line:
File "test.py", line 12
pass
^ TabError: inconsistent use of tabs and spaces in indentation
My code:
class eightPuzzle(StateSpace):
StateSpace.n = 0
def __init__(self, action, gval, state, parent = None):
StateSpace.__init__(self, action, gval, parent)
self.state = state
def successors(self) :
pass
You cannot mix tabs and spaces, according the PEP8 styleguide:
Spaces are the preferred indentation method.
Tabs should be used solely to remain consistent with code that is already indented with tabs.
Python 3 disallows mixing the use of tabs and spaces for indentation.
Python 2 code indented with a mixture of tabs and spaces should be converted to using spaces exclusively.
When invoking the Python 2 command line interpreter with the -t option, it issues warnings about code that illegally mixes tabs and spaces. When using -tt these warnings become errors. These options are highly recommended!
not using the backspace also is important (especially in the Leafpad editor). If you want to decrease indent, use only Alt_key + TAB
.
This should be done when you delete a line in a Python code.
open your code in a text editor, highlight all of it (ctr+a) and go to format and select either "Tabify region" or "Untabify region". It'll just make all the indents have the same format.
来源:https://stackoverflow.com/questions/28325553/tab-error-in-python