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.
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to