[Tutor] A strange problem...
Asrarahmed Kadri
ajkadri at googlemail.com
Sat Nov 11 15:16:44 CET 2006
Hi Folks,
I am trying to create a XML document and then writing it to a file, But the
porblem is that I have to run the program twice before the contents are
written to the file. Can you explain the reason for such a strange behaviour
?? The code is as below:
<CODE>
from elementtree import ElementTree as etree
info = etree.Element('info')
co1 = etree.SubElement(info,'company',name='google')
etree.SubElement(co1,'founder').text = 'Larry Page'
etree.SubElement(co1,'founder').text = 'Sergey Brin'
etree.SubElement(co1,'focus').text = 'Search Engine'
co2 = etree.SubElement(info,'company',name = 'NDTV')
etree.SubElement(co2,'founder').text = 'Pranoy Roy'
etree.SubElement(co2,'founder').text = 'Radhika Roy'
etree.SubElement(co2,'focus').text = '24/7 News Channel'
co3 = etree.SubElement(info,'company',name='WIPRO')
etree.SubElement(co3,'founder').text = 'Azim Premjee'
etree.SubElement(co3,'focus').text = 'IT Services'
fd = open('C:\\samtom.xml','w')
e = etree.tostring(info)
fd.write(e)
<END CODE>
--
To HIM you shall return.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061111/98eda53f/attachment-0001.htm
More information about the Tutor
mailing list