, - , text tail .
, ( stdlib 2.7 3.2, 2.6 3.1 ElementTree, lxml PyPI) tostring:
>>> s = '''<tag>
... Some <a>example</a> text
... </tag>'''
>>> t = ElementTree.fromstring(s)
>>> ElementTree.tostring(s, method='text')
'\n Some example text\n'
, . :
>>> ElementTree.tostring(s, method='text').strip()
'Some example text'
, , , , text tail s. ; , None. , :
def textify(t):
s = []
if t.text:
s.append(t.text)
for child in t.getchildren():
s.extend(textify(child))
if t.tail:
s.append(t.tail)
return ''.join(s)
, text tail str None. , , .