suppressing import errors

Chris Kaynor ckaynor at zindagigames.com
Tue Nov 15 12:24:03 EST 2011


As with any Python code, you can wrap the import into a try: except block.

try:
 import badModule
except:
 pass # Or otherwise handle the exception - possibly importing an
alternative module.

As with any except statement, specific exceptions may be caught
(rather than the blank, catch everything).

Chris

On Tue, Nov 15, 2011 at 9:11 AM, Andreea Babiuc <babiucandreea at gmail.com> wrote:
> Hi,
>
> Is there a way to suppress all the errors when importing a module in python?
>
> By that I mean.. If I have other imports in the module I'm trying to import
> that fail, I still want my module to be imported that way..
>
> Many thanks.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>



More information about the Python-list mailing list