Different kinds of Import Errors

Thomas Guettler hv at tbz-pariv.de
Tue Dec 4 11:23:29 EST 2007


Graham Dumpleton schrieb:
> What example did you use to test it? What version of Python are you
> using?

Yes, this changed. Python 2.3 includes the half imported module. Python 2.4 does not.
But the traceback of the exception contains the needed information:

Here are the two example files:

# foo.py
import sys
print sys.version
try:
    import foomod
except ImportError, exc:
    mods=sys.modules.keys()
    mods.sort()
    print mods
    import traceback
    print traceback.extract_tb(sys.exc_info()[2])

# foomod.py
import does_not_exist





More information about the Python-list mailing list