Python无缘无故地给出“IndentationError”

2024-05-20 23:01:52 发布

您现在位置: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

有人知道怎么解决这个问题吗?非常感谢。你知道吗


Tags: the代码infordataifdef错误