By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,742 Members | 1,327 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,742 IT Pros & Developers. It's quick & easy.

where is the Write method of ElementTree??

P: n/a
I'm messing around with trying to write an xml file using
xml.etree.ElementTree. All the examples on the internet show the use
of ElementTree.write(), although when I try to use it it's not
available, gives me ...

ElementTree(sectionElement).write("section.xml")
TypeError: 'module' object is not callable
I'm new to python, so I think I'm doing something wrong.. any
thoughts?

Thanks.'
See code below:

# Create xml structure
sectionElement = ElementTree.Element("section")

# step through feed result and create elements for each article -
result[article]
for article in feedResult:
articleElement = ElementTree.Element("article")

titleElement = ElementTree.SubElement(articleElement, "title")
titleElement.text = article['title']

bodyElement = ElementTree.SubElement(articleElement, "body")
bodyElement.text = article['body']

sectionElement.append(articleElement)

#print ElementTree.tostring(sectionElement)
ElementTree(sectionElement).write("section.xml")
Jun 27 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On May 23, 6:56 am, gray.bow...@gmail.com wrote:
I'm messing around with trying to write an xml file using
xml.etree.ElementTree. All the examples on the internet show the use
of ElementTree.write(), although when I try to use it it's not
available, gives me ...

ElementTree(sectionElement).write("section.xml")
TypeError: 'module' object is not callable

I'm new to python, so I think I'm doing something wrong.. any
thoughts?

Thanks.'

See code below:

# Create xml structure
sectionElement = ElementTree.Element("section")

# step through feed result and create elements for each article -
result[article]
for article in feedResult:
articleElement = ElementTree.Element("article")

titleElement = ElementTree.SubElement(articleElement, "title")
titleElement.text = article['title']

bodyElement = ElementTree.SubElement(articleElement, "body")
bodyElement.text = article['body']

sectionElement.append(articleElement)

#print ElementTree.tostring(sectionElement)
ElementTree(sectionElement).write("section.xml")
It's complaining about
ElementTree(whatever)
As it says, you are trying to call a module.

Looks like you need:
sectionElement.write("section.xml")

HTH,
John
Jun 27 '08 #2

P: n/a
gr*********@gmail.com wrote:
I'm messing around with trying to write an xml file using
xml.etree.ElementTree. All the examples on the internet show the use
of ElementTree.write(), although when I try to use it it's not
available, gives me ...

ElementTree(sectionElement).write("section.xml")
TypeError: 'module' object is not callable
I guess you did

from xml.etree import ElementTree

Then you should do this:

ElementTree.ElementTree(sectionElement).write("sec tion.xml")

sadly, the module names in ET are upper case and look like classes...

Stefan
Jun 27 '08 #3

P: n/a
On May 23, 3:22 am, Stefan Behnel <stefan...@behnel.dewrote:
gray.bow...@gmail.com wrote:
I'm messing around with trying to write an xml file using
xml.etree.ElementTree. All the examples on the internet show the use
of ElementTree.write(), although when I try to use it it's not
available, gives me ...
ElementTree(sectionElement).write("section.xml")
TypeError: 'module' object is not callable

I guess you did

from xml.etree import ElementTree

Then you should do this:

ElementTree.ElementTree(sectionElement).write("sec tion.xml")

sadly, the module names in ET are upper case and look like classes...

Stefan
That was it! Thanks to both of you for helping.

Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.