|
|
 |
 |
 |
 |
Python Programming Language
|
 |
 |
 |
 |
 |
 |
 |
 |
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
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.lang.python/browse_frm/thread/e09... Read carefully.
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.lang.python/browse_frm/thread/e09... > Read carefully.- Hide 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
saif.shak @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.lang.python/browse_frm/thread/e09... >> Read carefully.- Hide 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
On 11 May 2007 00:05:19 -0700, saif.shak@gmail.com <saif.shak @gmail.com> wrote: > 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
On May 11, 11:12 pm, "Jerry Hill" <malaclyp@gmail.com> wrote:
> On 11 May 2007 00:05:19 -0700, saif.shak @gmail.com > <saif.shak@gmail.com> wrote: > > 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
|
 |
 |
 |
 |
|