How to test if a module exists?

Steven D'Aprano steve at
Sat Nov 6 23:37:23 CET 2010

On Sat, 06 Nov 2010 13:54:09 -0700, Chris Rebert wrote:

> On Sat, Nov 6, 2010 at 1:01 PM, Mark Wooding <mdw at>
> wrote:
>> Chris Rebert <clp2 at> writes:
>>>     if err.message != "No module named extension_magic_module":
>> Ugh!  Surely this can break if you use Python with different locale
>> settings!
> Since when does Python have translated error messages?

Since Python 3.2.4. Or will it be 3.3.5? I will forget.


The point is that Python makes no promises about the error messages. The 
OP might be using a localised version, or some implementation that's not 
CPython, or the next version of Python might change the error message.

Hell, a user should be able to hack their personal copy of Python and 
customize the error strings without having to fear that code will break.


More information about the Python-list mailing list