How to test if a module exists?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Nov 6 18:37:23 EDT 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 distorted.org.uk>
> wrote:
>> Chris Rebert <clp2 at rebertia.com> 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.

*wink*

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.



-- 
Steven



More information about the Python-list mailing list