unindent与任何外部缩进级别都不匹配

时间:2012-08-01 10:33:54

标签: python indentation

  

可能重复:
  IndentationError: unindent does not match any outer indentation level

我写了下面的python代码,但我看不出是什么原因导致问题,但是我收到以下错误信息:

def post(self):                    ^ IndentationError:unindent与任何外部缩进级别都不匹配

class MainHandler(webapp2.RequestHandler):
def get(self):
    self.response.out.write(form)

def post(self):
    self.response.out.write("valid")

app = webapp2.WSGIApplication([('/', MainHandler)],debug=True)

任何帮助将不胜感激

2 个答案:

答案 0 :(得分:2)

您的代码示例充满了TAB字符。如果要将制表符与空格混合,则错误几乎是给定的。

使用python tabnanny清理源代码,将编辑器切换为仅使用空格,然后修复缩进:

python -m tabnanny -v path/to/your/code.py

答案 1 :(得分:0)

你混淆了空格和标签。运行python -tt中的脚本进行验证。

相关问题