Hi Elefterios, On Sun, May 8, 2011 at 12:18 PM, Elefterios Stamatogiannakis <est...@gmail.com> wrote: > You are exactly right, and i've more or less used code like the one you > presented. My only problem is that i believe that pypy shouldn't have > answered at my first example (In [12]:...) above that cElementTree > exists in xml.etree .Or maybe it should short circuit cElementTree to > point at ElementTree. To declare that something exists, and then when > somebody tries to use it, to throw an exception, isn't that nice.
Nothing we can do: the module cElementTree is actually written in Python also in CPython --- it is cElementTree.py --- but it import internally "_elementtree". So there is no way PyPy can know that cElementTree cannot be imported before actually trying to. The workaround to write "try: import cXxx; except ImportError: import xxx" is the general solution. It works in other cases too (cProfile, cPickle, cStringIO, etc). And also, it works in case the version of CPython you are running on misses some C extension modules. For example you would get the exact same error as you got on PyPy if you are running on a CPython where the C module "_elementree" was not compiled. A bientôt, Armin. _______________________________________________ pypy-dev@codespeak.net http://codespeak.net/mailman/listinfo/pypy-dev