472,964 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,964 software developers and data experts.

ElementTree in Python 2.5

Zver
2
Hey All!

I'm developing application that uses ElementTree for XML parsing. In python 2.5 ElementTree is part of standard "libs".

Now my question is. How would you detect version of python and then include the right ElementTree.

Psevdo-code :) ->
Expand|Select|Wrap|Line Numbers
  1. If python version < 2.4 then
  2. import elementtree.ElementTree as et
  3. else
  4. import xml.etree.ElementTree as et
  5.  
How to?
Dec 3 '07 #1
2 1629
bvdet
2,851 Expert Mod 2GB
Hey All!

I'm developing application that uses ElementTree for XML parsing. In python 2.5 ElementTree is part of standard "libs".

Now my question is. How would you detect version of python and then include the right ElementTree.

Psevdo-code :) ->
Expand|Select|Wrap|Line Numbers
  1. If python version < 2.4 then
  2. import elementtree.ElementTree as et
  3. else
  4. import xml.etree.ElementTree as et
  5.  
How to?
You can check your Python version like this:
Expand|Select|Wrap|Line Numbers
  1. >>> import sys
  2. >>> sys.version
  3. '2.3.5 (#62, Feb  8 2005, 16:23:02) [MSC v.1200 32 bit (Intel)]'
  4. >>> sys.version_info
  5. (2, 3, 5, 'final', 0)
  6. >>> sys.version_info[:2]
  7. (2, 3)
  8. >>> sys.version_info[:2] == (2,3)
  9. True
  10. >>> 
Dec 3 '07 #2
Zver
2
Final solution for this problem is possibly this:

Expand|Select|Wrap|Line Numbers
  1. try:
  2.  
  3.     import elementtree.ElementTree as et
  4.  
  5. except:
  6.  
  7.     try:
  8.  
  9.         import xml.etree.ElementTree as et
  10.  
  11.     except:
  12.  
  13.         print "No ElementTree in your Python!"
  14.  
Dec 4 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Greg Wilson | last post by:
I'm trying to convert from minidom to ElementTree for handling XML, and am having trouble with entities in DTDs. My Python script looks like this: ...
9
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...
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\
28
by: doug.bromley | last post by:
Why is the ElementTree API not a part of the Python core? I've recently been developing a script for accessing the Miva API only to find all the core API's provided by Python for parsing XML is...
15
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...
0
by: Greg Aumann | last post by:
I am trying to write some python code for a library that reads an XML-like language from a file into elementtree data structures. Then I want to be able to read and/or modify the structure and then...
2
by: mirandacascade | last post by:
Situation is this: 1) I have inherited some python code that accepts a string object, the contents of which is an XML document, and produces a data structure that represents some of the content of...
0
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:...
5
by: saif.shakeel | last post by:
#!/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":...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.