class TElement(ET._Element):

    def __init__(self, tag, text=None, tail=None, parent=None, attrib={},
        **extra):
        ET._Element.__init__(self, tag, dict(attrib, **extra))
if text:
    self.text = text
if tail:
    self.tail = tail
if not parent == None:
    parent.append(self)
How to set ElementTree Element text field in the constructor