473,326 Members | 2,438 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,326 software developers and data experts.

module error for elementtree

#!/usr/bin/env python
from elementtree import ElementTree as Element
tree = et.parse("testxml.xml")
for t in tree.getiterator("SERVICEPARAMETER"):
if t.get("Semantics") == "localId":
t.set("Semantics", "dataPackageID")
tree.write("output.xml")
Hi,
For the above code to work elementtree is
imported in first line ,but when running it says :
ImportError: No module named elementtree.ElementTree
Does thie module exists as default or a patch is needed?
Thanks

May 11 '07 #1
5 9965
On May 11, 12:05 am, saif.shak...@gmail.com wrote:
#!/usr/bin/env python

from elementtree import ElementTree as Element
tree = et.parse("testxml.xml")

for t in tree.getiterator("SERVICEPARAMETER"):
if t.get("Semantics") == "localId":
t.set("Semantics", "dataPackageID")

tree.write("output.xml")

Hi,
For the above code to work elementtree is
imported in first line ,but when running it says :
ImportError: No module named elementtree.ElementTree
Does thie module exists as default or a patch is needed?
Thanks
http://groups.google.com/group/comp....523a6e9b7061af

Read carefully.

May 11 '07 #2
On May 11, 12:22 pm, half.ital...@gmail.com wrote:
On May 11, 12:05 am, saif.shak...@gmail.com wrote:


#!/usr/bin/env python
from elementtree import ElementTree as Element
tree = et.parse("testxml.xml")
for t in tree.getiterator("SERVICEPARAMETER"):
if t.get("Semantics") == "localId":
t.set("Semantics", "dataPackageID")
tree.write("output.xml")
Hi,
For the above code to work elementtree is
imported in first line ,but when running it says :
ImportError: No module named elementtree.ElementTree
Does thie module exists as default or a patch is needed?
Thanks

http://groups.google.com/group/comp....frm/thread/e09...

Read carefully.- Hide quoted text -

- Show quoted text -
The commands are given in that link are more so for a linux system .I
am developing in windows.how should i go about to make it work

May 11 '07 #3
sa**********@gmail.com wrote:
On May 11, 12:22 pm, half.ital...@gmail.com wrote:
>On May 11, 12:05 am, saif.shak...@gmail.com wrote:


>>#!/usr/bin/env python
from elementtree import ElementTree as Element
tree = et.parse("testxml.xml")
for t in tree.getiterator("SERVICEPARAMETER"):
if t.get("Semantics") == "localId":
t.set("Semantics", "dataPackageID")
tree.write("output.xml")
Hi,
For the above code to work elementtree is
imported in first line ,but when running it says :
ImportError: No module named elementtree.ElementTree
Does thie module exists as default or a patch is needed?
Thanks
http://groups.google.com/group/comp....frm/thread/e09...

Read carefully.- Hide quoted text -

- Show quoted text -

The commands are given in that link are more so for a linux system .I
am developing in windows.how should i go about to make it work
As said: read carefully.

Stefan
May 11 '07 #4
On 11 May 2007 00:05:19 -0700, sa**********@gmail.com
<sa**********@gmail.comwrote:
For the above code to work elementtree is
imported in first line ,but when running it says :
ImportError: No module named elementtree.ElementTree
Does thie module exists as default or a patch is needed?
That depends on which version of Python you are running. Starting
with 2.5, ElementTree was moved into the standard library, as part of
the xml package. If you're using an older version of python, I think
you'll need to download and install the elementtree package from
http://effbot.org/zone/element-index.htm

Assuming you're using python 2.5, you probably want something like this:

from xml.etree.ElementTree import ElementTree as et

--
Jerry
May 11 '07 #5
On May 11, 11:12 pm, "Jerry Hill" <malaclyp...@gmail.comwrote:
On 11 May 2007 00:05:19 -0700, saif.shak...@gmail.com

<saif.shak...@gmail.comwrote:
For the above code to work elementtree is
imported in first line ,but when running it says :
ImportError: No module named elementtree.ElementTree
Does thie module exists as default or a patch is needed?

That depends on which version of Python you are running. Starting
with 2.5, ElementTree was moved into the standard library, as part of
the xml package. If you're using an older version of python, I think
you'll need to download and install the elementtree package fromhttp://effbot.org/zone/element-index.htm

Assuming you're using python 2.5, you probably want something like this:

from xml.etree.ElementTree import ElementTree as et
1. The OP appears to be confusing ElementTree and Element (objects of
the first class are containers of objects of the second class).

2. For any serious work to be done efficiently, the cElementTree
module should be used.

3. Here's some code that appears to work for supporting multiple
versions of Python:

8< --- import_et.py ---
import sys
python_version = sys.version_info[:2]
print >sys.stderr, "Python version:", sys.version_info
if python_version >= (2, 5):
import xml.etree.cElementTree as ET
else:
try:
import cElementTree as ET
except ImportError:
try:
import ElementTree as ET
except ImportError:
msg = "\nYou need the [c]ElementTree package\n" \
"from http://effbot.org/downloads/\n\n"
sys.stderr.write(msg)
raise
print >sys.stderr, "ET imported from", ET.__file__
8< --- end of import_et.py ---

4. and some (occasionally astonishing) results:

C:\junk>for %v in (5,1,4) do \python2%v\python import_et.py

C:\junk>\python25\python import_et.py
Python version: (2, 5, 1, 'final', 0)
ET imported from C:\python25\lib\xml\etree\cElementTree.pyc

C:\junk>\python21\python import_et.py
Python version: (2, 1, 3, 'final', 0)
ET imported from C:\python21\cElementTree.pyd

C:\junk>\python24\python import_et.py
Python version: (2, 4, 3, 'final', 0)
ET imported from C:\Documents and Settings\sjm\Application Data\Python-
Eggs\celementtree-1.0.5_20051216-py2.4-win32.egg-tmp\cElementTree.pyd

IIRC, I have TurboGears (a leading contender for the "All of your
sys.path are belong to us" award) to thank for that little gem :-)

HTH,
John

May 12 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Stewart Midwinter | last post by:
I want to parse a file with ElementTree. My file has the following format: <!-- file population.xml --> <?xml version='1.0' encoding='utf-8'?> <population> <person><name="joe" sex="male"...
1
by: Beowulf | last post by:
Hello, I'm using Python to automate admin tasks on my job. We use Windoze 2000 as desktop platform. When executing this daily backup scripts I get the following error: Traceback (most recent...
0
by: Calvin Spealman | last post by:
I've been working on a small test runner script, to accumulate my test scripts (all python files in the 'test' sub-directories of my source tree). Things were going well, but I'm still having...
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\
1
by: Mullin Yu | last post by:
my web services is reference a vb6 com dll, and if it's registered at the local machine, the web service is working. but, if i put the dll to a z: which is mapping to a network driver and...
1
by: Bilwanath | last post by:
Hi, We r using VR(version 3.1) 3d for photogrammetry.This software is developed using Python.When I m using Easygui in Pyhton it is giving error as No module is found. Pls,I can know any sol. for...
5
by: sawilla | last post by:
First, I'm new to Python. I'm getting and error when I run Python 2.5.2 as a regular user in Vista but not when I run Python as an administrator. For example, if I type "import numpy" after I...
4
by: vincehofmeister | last post by:
Hey everyone: I am using py2exe and everything is working fine except one module, ClientCookie, found here: http://wwwsearch.sourceforge.net/ClientCookie/ Keeps coming up as not found no...
3
by: špela | last post by:
Hi. I have installed elementtree to python, but it now doesn't work: >>> from elementtree import ElementTree Traceback (most recent call last): File "<pyshell#8>", line 1, in <module> ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
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...
1
isladogs
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
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...
1
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)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.