[issue13796] use 'text=...' to define the text attribute of and xml.etree.ElementTree.Element
Pedro Andres Aranda Gutierrez
report at bugs.python.org
Mon Jan 16 08:21:27 CET 2012
New submission from Pedro Andres Aranda Gutierrez <paaguti at gmail.com>:
I have extended the xml.etree.ElementTree.Element class and pass the text attribute in the arguments. This creates much more compact code:
import xml.etree.ElementTree as xml
class Element(xml.Element):
def __init__(self,tag,attrib={},**attrs):
super(xml.Element,self).__init__()
self.tag = tag
self.attrib = attrib
self.attrib.update(attrs)
self.text = self.attrib.pop('text',None)
self.tail = self.attrib.pop('tail',None)
self._children = []
if __name__ == '__main__':
from sys import stdout
test = Element('Hello',)
test2 = Element('World',{'humour':'excelent'},text = 'How do you do', tail="Fine")
test.append(test2)
xml.ElementTree(test).write(stdout,encoding="utf-8",xml_declaration="yes",method="xml")
----------
messages: 151336
nosy: paaguti
priority: normal
severity: normal
status: open
title: use 'text=...' to define the text attribute of and xml.etree.ElementTree.Element
type: enhancement
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13796>
_______________________________________
More information about the Python-bugs-list
mailing list