469,583 Members | 2,590 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,583 developers. It's quick & easy.

where is the Write method of ElementTree??

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
3 1881
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
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
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.

Similar topics

4 posts views Thread by Lonnie Princehouse | last post: by
4 posts views Thread by alainpoint | last post: by
9 posts views Thread by Chris Spencer | last post: by
1 post views Thread by mirandacascade | last post: by
1 post views Thread by mirandacascade | last post: by
15 posts views Thread by Steven Bethard | last post: by
reply views Thread by Mark E. Smith | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.