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
不。我所做的只是刪除文檔字符串評論。到底是怎麼回事?
請注意,通常執行速度更快:rc = [],rc.append(node.data),return''.join(rc)。這是因爲你不需要每次都創建一個新的字符串。 – EOL 2010-02-11 10:33:33
'return''.join(n.data for n在nodelist中,如果n.nodeType == n.TEXT_NODE)' – 2018-02-06 06:19:29