How to test if a module exists?

Jon Dufresne jon.dufresne at gmail.com
Tue Nov 9 13:06:39 EST 2010


On Tue, Nov 9, 2010 at 4:30 AM, Roy Smith <roy at panix.com> wrote:
> In article <ibatkk$t7p$4 at lust.ihug.co.nz>,
>  Lawrence D'Oliveiro <ldo at geek-central.gen.new_zealand> wrote:
>
>> In message <roy-4C92BB.16523506112010 at news.panix.com>, Roy Smith wrote:
>>
>> > On the other hand, if your module's bug is that it in turn imports some
>> > other module, which doesn't exist, you'll also get an ImportError.
>>
>> Does it really matter? Either way, the module is unusable.
>
> If I understand correctly, he's trying to differentiate between:
>
> 1) The module is unusable because it's not installed
>
> 2) The module is unusable because it has a bug in it.
>


Yes. Case 1 is an acceptable case. In case 1, if the extension module
(extension as in extension to my core program) does not have magic.py
then the extension adds no behavior in the magic1 portion of the
program. However, if the extension does have magic.py but it is buggy
(case 2), I want my program to fail. Currently I am doing this using
the traceback code suggested in an earlier post.



More information about the Python-list mailing list