Then how do I import that? I run everything in python 2.4, but one of my scripts import xml.etree.ElementTree...which is only Python 2.5
views:
121answers:
4Then it fails.
You can't import a python 2.5 library while you're running python 2.4. It won't work.
Why can't you run python 2.5+?
Consider upgrading to Python 2.5 (or, dare I say, 2.6!-) one of these decades... the times, they are a'changin'! Meanwhile, for ElementTree in particular, you might manage to back-patch it, but...
Come gather 'round people
Wherever you roam
And admit that the waters
Around you have grown
And accept it that soon
You'll be drenched to the bone.
If your time to you
Is worth savin'
Then you better start swimmin'
Or you'll sink like a stone
For the times they are a-changin'.
And if hearing it in great music helps you, feel free... but you'd better start swimmin', or you'll sink like a stone...!-)
This type of problem is not all that unusual, as not everyone has control over the version of Python that they use. A few years ago I had this very problem as most of my work took place on a Windows PC, but at one point we needed to run it on a large UNIX box which was subject to strict change control, meaning that I couldn't install Python 2.5. I think even now that box may be running Python 2.4.
Looking back on my solution, it wasn't particularly elegant, but here it is...
while True:
try:
from xml.etree.cElementTree import *
break
except ImportError:
pass
try:
from xml.etree.ElementTree import *
break
except ImportError:
pass
try:
from cElementTree import *
break
except ImportError:
pass
from ElementTree import *
break
This was part of a module called xmlutils.py which was used by the rest of my code rather than importing xml.etree.ElementTree (or whatever) directly.
Edit: I should point out that cElementTree and ElementTree were the names for xml.etree.cElementTree and xml.etree.ElementTree before they became part of the standard library.
You should be able to install ElementTree for Python 2.4. It is in debian under the package name python2.4-elementtree
(and ..-celementtree
)
If you don't find a package for your OS, you can install it right from Source.