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") 3 2059
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 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
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
by: Kenneth McDonald |
last post by:
I have a module I'd like to document using the same style...
Thanks,
Ken
|
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>...
|
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\
|
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...
|
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...
|
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:...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM).
In this month's session, the creator of the excellent VBE...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: Aftab Ahmad |
last post by:
Hello Experts!
I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: marcoviolo |
last post by:
Dear all,
I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
| |