Python中的制表符错误 [英] Tab Error in Python
本文介绍了Python中的制表符错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下python代码抛出此错误消息,但我不知道为什么,我的标签页似乎对齐:
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
我的代码:
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
推荐答案
根据 空格是首选的缩进方法.
制表符应仅用于与已经使用制表符缩进的代码保持一致.
Python 3不允许混合使用制表符和空格进行缩进.
Python 3 disallows mixing the use of tabs and spaces for indentation.
由制表符和空格组成的缩进的Python 2代码应仅转换为使用空格.
Python 2 code indented with a mixture of tabs and spaces should be converted to using spaces exclusively.
使用-t选项调用Python 2命令行解释器时,它会发出有关非法混用制表符和空格的代码的警告.当使用-tt时,这些警告变为错误.强烈建议使用这些选项!
这篇关于Python中的制表符错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文