473,378 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 2064
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Lonnie Princehouse | last post by:
I've run into some eccentric behavior... It appears that one of my modules is being cut off at exactly 2^14 characters when I try to import it. Has anyone else encountered this? I can't find any...
4
by: alainpoint | last post by:
Hello, I use Elementtree to parse an elementary SVG file (in fact, it is one of the examples in the "SVG essentials" book). More precisely, it is the fig0201.svg file in the second chapter. The...
9
by: Chris Spencer | last post by:
Does anyone know how to make ElementTree preserve namespace prefixes in parsed xml files? The default behavior is to strip a document of all prefixes and then replace them autogenerated prefixes...
9
by: Kenneth McDonald | last post by:
I have a module I'd like to document using the same style... Thanks, Ken
1
by: mirandacascade | last post by:
I do not understand how to use the find() method in ElementTree. The file 'sample.xml' is: <?xml version="1.0"?> <SampleRoot> <Header> <Product>FindMystery</Product> </Header>...
1
by: mirandacascade | last post by:
O/S: Windows 2K Vsn of Python: 2.4 Currently: 1) Folder structure: \workarea\ <- ElementTree files reside here \xml\ \dom\
15
by: Steven Bethard | last post by:
I'm having trouble using elementtree with an XML file that has some gbk-encoded text. (I can't read Chinese, so I'm taking their word for it that it's gbk-encoded.) I always have trouble with...
0
by: Mark E. Smith | last post by:
cElementTree cannot hold ElementTree instances. #from elementtree.ElementTree import ElementTree, dump # This works from cElementTree import ElementTree, dump # This does not from...
0
by: Mark | last post by:
-------- Original Message -------- Subject: Using cElementTree and elementtree.ElementInclude Date: Mon, 23 Oct 2006 09:40:24 -0500 From: Mark E. Smith <mark.e.smith@arnold.af.mil> Organization:...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.