(python)docstring导致缩进错误

时间:2010-02-11 08:01:03

标签: python indentation

def getText(nodelist):
    """Extracts the text between XML tags

    I took this directly from http://docs.python.org/library/xml.dom.minidom.html.
    For example, if I have a tag <Tag>525</Tag> this method returns me '525'
    """
    rc = ""
    for node in nodelist:
        if node.nodeType == node.TEXT_NODE:
            rc = rc + node.data
    return rc

给我IndentationError: unindent does not match any outer indentation level

def getText(nodelist):
    rc = ""
    for node in nodelist:
        if node.nodeType == node.TEXT_NODE:
            rc = rc + node.data
    return rc

没有。我所做的只是删除文档字符串注释。发生了什么事?

2 个答案:

答案 0 :(得分:15)

您的docstring以制表符开头。使代码仅使用空格进行缩进(或仅使用制表符),包括文档字符串的缩进。

答案 1 :(得分:3)

确保没有为缩进混合空格和制表符