Python没有明显的原因给出“IndentationError”

时间:2013-06-16 12:55:03

标签: python

我有这个简短的代码片段,它不起作用,并继续给我这个错误:

iMac-di-Luca:~ luca$ ./peasantlr.py | File "./peasantlr.py", line 24 | for char in data: | IndentationError: unindent does not match any outer indentation level

我在代码中找不到任何错误...我已经检查过,并且没有无效的ASCII字符可能导致此错误。

#!/usr/bin/env python

def posts(data):

    postdata = ""

    for char in data:
        # If it's a non-escaped {, then it's the beginning of a post.
        if char == "{":
            insidepost = True
            # Skip to the char after {, start copying from there
            continue
        # If it's a non-escaped }, yield the post, and clean the buffer.
        if char == "}":
            insidepost = False
            yield postdata.replace("&lc;","{").replace("&rc;","}")
            postdata = ""
        # While in a post, copy the data into the post buffer.
        if insidepost:
            postdata += char

def findtags(data):
    tagdata = ""
    for char in data: *[This is the line which causes the error]*
        if char == "[":
            insidetag = True
            continue
        if char == "]":
            insidetag = False
            yield postdata
            postdata = ""
        if insidepost:
            postdata += char


f = """{A}{B}{c}{dDD}"""
for f in posts(f): print f

有谁知道如何解决这个问题?非常感谢提前。

2 个答案:

答案 0 :(得分:4)

您已将标签与空格混合,您不应该这样做。每PEP 8 Style Guide个空格的使用多于制表符,所以请尝试使用空格:D。

答案 1 :(得分:0)

检查是否存在标签。例如:在vim的正常模式下,键入:/\t