homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author paaguti
Recipients paaguti
Date 2012年01月16日.07:21:26
SpamBayes Score 1.3370574e-05
Marked as misclassified No
Message-id <1326698487.2.0.0622950382199.issue13796@psf.upfronthosting.co.za>
In-reply-to
Content
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")
History
Date User Action Args
2012年01月16日 07:21:27paagutisetrecipients: + paaguti
2012年01月16日 07:21:27paagutisetmessageid: <1326698487.2.0.0622950382199.issue13796@psf.upfronthosting.co.za>
2012年01月16日 07:21:26paagutilinkissue13796 messages
2012年01月16日 07:21:26paaguticreate

AltStyle によって変換されたページ (->オリジナル) /