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
Cung cấp cho tôi IndentationError: unindent does not match any outer indentation level
(python) docstring đang gây ra thụt đầu dòng lỗi
def getText(nodelist):
rc = ""
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc = rc + node.data
return rc
Không. Tất cả những gì tôi đang làm là xóa nhận xét docstring. Chuyện gì vậy?
Lưu ý rằng thường nhanh hơn: rc = [], rc.append (node.data), trả về '' .join (rc). Điều này là do bạn không cần tạo chuỗi mới mỗi lần. – EOL
'return '' .join (n.data cho n trong nodelist nếu n.nodeType == n.TEXT_NODE)' –