-1

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

iMac-di-Luca:~ luca$ ./peasantlr.py |  文件

我真的没有在我的代码中发现任何错误......我已经检查过,并且没有可能导致此错误的无效 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

有谁知道如何解决这一问题?提前谢谢了。

4

2 回答 2

4

您将制表符与空格混合在一起,这是您不应该做的。根据PEP 8 样式指南,空格的使用比制表符多,因此请尝试使用空格:D。

于 2013-06-16T13:06:45.447 回答
0

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

于 2013-06-16T13:04:31.730 回答