Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #15724

Re: suppressing import errors

References <CAC82khmG+zH3Cd5pRfou+0FED18MHfizLzJL4EM+V+Pw+q17+w@mail.gmail.com>
From Chris Kaynor <ckaynor@zindagigames.com>
Date 2011-11-15 09:24 -0800
Subject Re: suppressing import errors
Newsgroups comp.lang.python
Message-ID <mailman.2735.1321377867.27778.python-list@python.org> (permalink)

Show all headers | View raw


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@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
>
>

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: suppressing import errors Chris Kaynor <ckaynor@zindagigames.com> - 2011-11-15 09:24 -0800

csiph-web