[Tutor] How to get module name from ImportError

Nikunj.Badjatya at emc.com Nikunj.Badjatya at emc.com
Mon Nov 21 07:23:21 CET 2011

Exactly !
Thanks a lot.

From: Christian Witts [mailto:cwitts at compuscan.co.za]
Sent: Monday, November 21, 2011 11:36 AM
To: Badjatya, Nikunj
Cc: tutor at python.org
Subject: Re: [Tutor] How to get module name from ImportError

On 2011/11/21 07:54 AM, Nikunj.Badjatya at emc.com<mailto:Nikunj.Badjatya at emc.com> wrote:
Hi All,

Please look at the following snippet.

# User defined modules
    from scripts import precheck
    from scripts import validate
    from scripts import constants
except ImportError:
    print("ERROR: One of the modules (..scripts/precheck.py, validate.py, constants) is not present.")
    print("INFO : Please verify the above modules, and restart the installation")


See the red line.
I want to get the name of the particular module which is not available and hence causing ImportError.
One of the ways can be to get the STDERR and process it using re. !?

Is there a better alternate available .?



Tutor maillist  -  Tutor at python.org<mailto:Tutor at python.org>

To unsubscribe or change subscription options:

>>> try:
...     import nothing
... except ImportError, err_msg:
...     print err_msg
No module named nothing

Hope that helps.

Christian Witts
Python Developer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111121/283d3e3a/attachment-0001.html>

More information about the Tutor mailing list