By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,923 Members | 1,443 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,923 IT Pros & Developers. It's quick & easy.

module error for elementtree

P: n/a
#!/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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.