473,657 Members | 2,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

where is the Write method of ElementTree??

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

ElementTree(sec tionElement).wr ite("section.xm l")
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.Ele ment("section")

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

titleElement = ElementTree.Sub Element(article Element, "title")
titleElement.te xt = article['title']

bodyElement = ElementTree.Sub Element(article Element, "body")
bodyElement.tex t = article['body']

sectionElement. append(articleE lement)

#print ElementTree.tos tring(sectionEl ement)
ElementTree(sec tionElement).wr ite("section.xm l")
Jun 27 '08 #1
3 2080
On May 23, 6:56 am, gray.bow...@gma il.com wrote:
I'm messing around with trying to write an xml file using
xml.etree.Eleme ntTree. All the examples on the internet show the use
of ElementTree.wri te(), although when I try to use it it's not
available, gives me ...

ElementTree(sec tionElement).wr ite("section.xm l")
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.Ele ment("section")

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

titleElement = ElementTree.Sub Element(article Element, "title")
titleElement.te xt = article['title']

bodyElement = ElementTree.Sub Element(article Element, "body")
bodyElement.tex t = article['body']

sectionElement. append(articleE lement)

#print ElementTree.tos tring(sectionEl ement)
ElementTree(sec tionElement).wr ite("section.xm l")
It's complaining about
ElementTree(wha tever)
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*********@gma il.com wrote:
I'm messing around with trying to write an xml file using
xml.etree.Eleme ntTree. All the examples on the internet show the use
of ElementTree.wri te(), although when I try to use it it's not
available, gives me ...

ElementTree(sec tionElement).wr ite("section.xm l")
TypeError: 'module' object is not callable
I guess you did

from xml.etree import ElementTree

Then you should do this:

ElementTree.Ele mentTree(sectio nElement).write ("section.xm l")

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...@behn el.dewrote:
gray.bow...@gma il.com wrote:
I'm messing around with trying to write an xml file using
xml.etree.Eleme ntTree. All the examples on the internet show the use
of ElementTree.wri te(), although when I try to use it it's not
available, gives me ...
ElementTree(sec tionElement).wr ite("section.xm l")
TypeError: 'module' object is not callable

I guess you did

from xml.etree import ElementTree

Then you should do this:

ElementTree.Ele mentTree(sectio nElement).write ("section.xm l")

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
1514
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 mention of such a bug, and stranger yet, other modules that exceed 16384 characters seem to work just fine. In particular, suppose that my module foo.py contains the following as its last line: thing = "goodbye world"
4
3727
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 contents of the file are as follows (i hope it will be rendered correctly): <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> <svg width="200" height="200">
9
10090
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 like ns0, ns1, etc. The correct behavior should be to write the file in the form that it was read, which it seems to do correctly for everything except namespace prefixes. The docs mention "proper" output can be achieved by using the Qname object,...
9
1747
by: Kenneth McDonald | last post by:
I have a module I'd like to document using the same style... Thanks, Ken
1
3962
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> <SpecificInformation>
1
3062
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
5415
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 encodings, so I'm sure I'm just screwing something simple up. Can anyone help me? Here's the interactive session. Sorry it's a little verbose, but I figured it would be better to include too much than not enough. I basically expected...
0
1109
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 elementtree import ElementInclude etree = ElementTree(file='xml_in.xml').getroot()
0
1267
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: AEDC To: python-list@python.org
0
8382
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8297
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8498
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8600
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7311
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1930
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.