[Tutor] How to get module name from ImportError
Christian Witts
cwitts at compuscan.co.za
Mon Nov 21 07:06:24 CET 2011
On 2011/11/21 07:54 AM, Nikunj.Badjatya at emc.com wrote:
>
> Hi All,
>
> Please look at the following snippet.
>
> {{{
>
> # User defined modules
>
> try:
>
> 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")
>
> sys.exit(1)
>
> }}}
>
> 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 .?
>
> Thanks
>
> Nikunj
>
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>>> 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/0e22ff57/attachment.html>
More information about the Tutor
mailing list