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
Donne-moi IndentationError: unindent does not match any outer indentation level
(python) docstring provoque une erreur d'indentation
def getText(nodelist):
rc = ""
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc = rc + node.data
return rc
ne fonctionne pas. Tout ce que je fais est de supprimer le commentaire Docstring. Que se passe-t-il?
Notez qu'il est généralement plus rapide à faire: rc = [], rc.append (node.data), return '' .join (rc). C'est parce que vous n'avez pas besoin de créer une nouvelle chaîne à chaque fois. – EOL
'return '' .join (n.data pour n dans nodelist si n.nodeType == n.TEXT_NODE)' –